Example #1
0
    def POST(self):
        # Initialize the SMART client (will raise excepton if the credentails are bad)
        smart_client = get_smart_client()

        # Load the message parameters
        sender = web.input().sender_email
        recipient = web.input().recipient_email
        subject = SMART_DIRECT_PREFIX + web.input().subject
        message = web.input().message
        apps = string.split(web.input().apps, ",")
        apis = []

        # Generate the end-point direct addresses for the first message hop
        me = SMTP_USER_ALT + "@" + SMTP_HOST_ALT
        you = SMTP_USER + "@" + SMTP_HOST

        # Load and parse the apps manifests JSON
        myapps = json.loads(get_apps().GET())

        # Initialize the outbound manifest data object
        manifest = {"from": sender, "to": recipient, "apps": []}

        # Populate the manifest object with a subset of the manifest data
        # for the selected apps. Also build a list of the APIs needed by the
        # selected aps.
        for a in myapps:
            if a["id"] in apps:
                if "requires" in a.keys():
                    myapis = a["requires"].keys()
                    for i in myapis:
                        if i not in apis and "GET" in a["requires"][i]["methods"]:
                            apis.append(i)
                    del (a["requires"])
                manifest["apps"].append({"id": a["id"], "version": a["version"]})

        # Load the manifest in a string buffer (in JSON format)
        manifesttxt = json.dumps(manifest, sort_keys=True, indent=4)
        manifestbuffer = StringIO()
        manifestbuffer.write(manifesttxt)

        # Build the patient RDF graph with the demographics
        rdfres = smart_client.records_X_demographics_GET().graph

        # Augment the RDF graph with the needed data models (except demographics)
        for a in apis:
            call = get_call(a)
            if call != "records_X_demographics_GET":
                method_to_call = getattr(smart_client, get_call(a))
                rdfres += method_to_call().graph

        # Anonymize the RDF graph for export
        rdfres = anonymize_smart_rdf(rdfres)

        # Serialize the RDF graph in a string buffer
        rdftext = rdfres.serialize()
        rdfbuffer = StringIO()
        rdfbuffer.write(rdftext)

        # Initialize the attachments descriptor object
        attachments = [
            {"file_buffer": rdfbuffer, "name": "patient.xml", "mime": "text/xml"},
            {"file_buffer": manifestbuffer, "name": "manifest.json", "mime": "text/xml"},
        ]

        # Initialize the mailer settings
        settings = {"host": SMTP_HOST_ALT, "user": SMTP_USER_ALT, "password": SMTP_PASS_ALT}

        # Send the SMART Direct message
        send_message(me, you, subject, message, message, attachments, settings)

        # Clean up the string buffers
        manifestbuffer.close()
        rdfbuffer.close()

        # If needed, add the recipient to the app's preferences
        if web.input().recipient_add == "true":
            add_recipient(smart_client, recipient)

        # Respond with success message
        return json.dumps({"result": "ok"})
Example #2
0
    def POST(self):
        # First, try setting up a dummy SMART client to test the credentials
        # for securty reasons (will raise excepton if the credentails are bad)
        get_smart_client()
        
        # Initialize the SMART client
        smart_client = get_smart_client()

        # Load the message parameters
        sender = web.input().sender_email
        recipient = web.input().recipient_email
        subject = SMART_DIRECT_PREFIX + web.input().subject
        message = web.input().message
        apps = string.split (web.input().apps, ",")
        apis = []
    
        # Generate the end-point direct addresses for the first message hop
        me = SMTP_USER_ALT + "@" + SMTP_HOST_ALT
        you = SMTP_USER + "@" + SMTP_HOST
        
        # Load the app manifests JSON 
        FILE = open(APP_PATH + '/data/apps.json', 'r')
        APPS_JSON = FILE.read()
        FILE.close()
        
        # Parse the apps manifests JSON
        myapps = json.loads(APPS_JSON)
        
        # Initialize the outbound manifest data object
        manifest= {"from": sender,
                   "to": recipient,
                   "apps": []}
        
        # Populate the manifest object with a subset of the manifest data
        # for the selected apps. Also build a list of the APIs needed by the
        # selected aps.
        for a in myapps:
            if (a['id'] in apps):
                myapis = a['apis']
                for i in myapis:
                    if (i not in apis):
                        apis.append(i)
                del(a['apis'])
                del(a['name'])
                del(a['icon'])
                manifest["apps"].append(a)
        
        # Load the manifest in a string buffer (in JSON format)
        manifesttxt = json.dumps(manifest)
        manifestbuffer = StringIO()
        manifestbuffer.write(manifesttxt)
        
        # Build the patient RDF graph
        rdfres = smart_client.records_X_demographics_GET()
        
        if ("problems" in apis):
            rdfres += smart_client.records_X_problems_GET()
            
        if ("medications" in apis):
            rdfres += smart_client.records_X_medications_GET()
            
        if ("vital_signs" in apis):
            rdfres += smart_client.records_X_vital_signs_GET() 
        
        # Anonymize the RDF graph for export
        rdfres = anonymize_smart_rdf (rdfres)
        
        # Serialize the RDF graph in a string buffer
        rdftext = rdfres.serialize()
        rdfbuffer = StringIO()
        rdfbuffer.write(rdftext)
        
        # Initialize the attachments descriptor object
        attachments = [
            {'file_buffer': rdfbuffer, 'name': "patient.xml", 'mime': "text/xml"},
            {'file_buffer': manifestbuffer, 'name': "manifest.json", 'mime': "text/xml"}
        ]
        
        # Initialize the mailer settings
        settings = {'host': SMTP_HOST_ALT, 'user': SMTP_USER_ALT, 'password': SMTP_PASS_ALT}
        
        # Send the SMART Direct message
        send_message (me, you, subject, message, message, attachments, settings)
        
        # Clean up the string buffers
        manifestbuffer.close()
        rdfbuffer.close()
        
        # Respond with success message
        return json.dumps({'result': 'ok'})
Example #3
0
    def POST(self):        
        # Initialize the SMART client (will raise excepton if the credentails are bad)
        smart_client = get_smart_client()

        # Load the message parameters
        sender = web.input().sender_email
        recipient = web.input().recipient_email
        subject = SMART_DIRECT_PREFIX + web.input().subject
        message = web.input().message
        apps = string.split (web.input().apps, ",")
        apis = []
    
        # Generate the end-point direct addresses for the first message hop
        me = SMTP_USER_ALT + "@" + SMTP_HOST_ALT
        you = SMTP_USER + "@" + SMTP_HOST
        
        # Load and parse the apps manifests JSON
        myapps = json.loads(get_apps().GET())
        
        # Initialize the outbound manifest data object
        manifest= {"from": sender,
                   "to": recipient,
                   "apps": []}
        
        # Populate the manifest object with a subset of the manifest data
        # for the selected apps. Also build a list of the APIs needed by the
        # selected aps.        
        for a in myapps:
            if (a['id'] in apps):
                if 'requires' in a.keys():
                    myapis = a['requires'].keys()
                    for i in myapis:
                        if (i not in apis and 'GET' in a['requires'][i]['methods']):
                            apis.append(i)
                    del(a['requires'])
                manifest["apps"].append({'id': a['id'], 'version': a['version']})
        
        # Load the manifest in a string buffer (in JSON format)
        manifesttxt = json.dumps(manifest, sort_keys=True, indent=4)
        manifestbuffer = StringIO()
        manifestbuffer.write(manifesttxt)

        # Build the patient RDF graph with the demographics
        rdfres = smart_client.records_X_demographics_GET().graph
        
        # Augment the RDF graph with the needed data models (except demographics)
        for a in apis:
            call = get_call(a)
            if call != "records_X_demographics_GET":
                method_to_call = getattr(smart_client, get_call(a))
                rdfres += method_to_call().graph

        # Anonymize the RDF graph for export
        rdfres = anonymize_smart_rdf (rdfres)
        
        # Serialize the RDF graph in a string buffer
        rdftext = rdfres.serialize()
        rdfbuffer = StringIO()
        rdfbuffer.write(rdftext)
        
        # Initialize the attachments descriptor object
        attachments = [
            {'file_buffer': rdfbuffer, 'name': "patient.xml", 'mime': "text/xml"},
            {'file_buffer': manifestbuffer, 'name': "manifest.json", 'mime': "text/xml"}
        ]
        
        # Initialize the mailer settings
        settings = {'host': SMTP_HOST_ALT, 'user': SMTP_USER_ALT, 'password': SMTP_PASS_ALT}
        
        # Send the SMART Direct message
        send_message (me, you, subject, message, message, attachments, settings)
        
        # Clean up the string buffers
        manifestbuffer.close()
        rdfbuffer.close()
        
        # If needed, add the recipient to the app's preferences
        if web.input().recipient_add == "true": add_recipient (smart_client, recipient)
        
        # Respond with success message
        return json.dumps({'result': 'ok'})
Example #4
0
    def POST(self):
        # First, try setting up a dummy SMART client to test the credentials
        # for securty reasons (will raise excepton if the credentails are bad)
        get_smart_client()

        # Initialize the SMART client
        smart_client = get_smart_client()

        # Load the message parameters
        sender = web.input().sender_email
        recipient = web.input().recipient_email
        subject = SMART_DIRECT_PREFIX + web.input().subject
        message = web.input().message
        apps = string.split(web.input().apps, ",")
        apis = []

        # Generate the end-point direct addresses for the first message hop
        me = SMTP_USER_ALT + "@" + SMTP_HOST_ALT
        you = SMTP_USER + "@" + SMTP_HOST

        # Load the app manifests JSON
        FILE = open(APP_PATH + '/data/apps.json', 'r')
        APPS_JSON = FILE.read()
        FILE.close()

        # Parse the apps manifests JSON
        myapps = json.loads(APPS_JSON)

        # Initialize the outbound manifest data object
        manifest = {"from": sender, "to": recipient, "apps": []}

        # Populate the manifest object with a subset of the manifest data
        # for the selected apps. Also build a list of the APIs needed by the
        # selected aps.
        for a in myapps:
            if (a['id'] in apps):
                myapis = a['apis']
                for i in myapis:
                    if (i not in apis):
                        apis.append(i)
                del (a['apis'])
                del (a['name'])
                del (a['icon'])
                manifest["apps"].append(a)

        # Load the manifest in a string buffer (in JSON format)
        manifesttxt = json.dumps(manifest)
        manifestbuffer = StringIO()
        manifestbuffer.write(manifesttxt)

        # Build the patient RDF graph
        rdfres = smart_client.records_X_demographics_GET()

        if ("problems" in apis):
            rdfres += smart_client.records_X_problems_GET()

        if ("medications" in apis):
            rdfres += smart_client.records_X_medications_GET()

        if ("vital_signs" in apis):
            rdfres += smart_client.records_X_vital_signs_GET()

        # Anonymize the RDF graph for export
        rdfres = anonymize_smart_rdf(rdfres)

        # Serialize the RDF graph in a string buffer
        rdftext = rdfres.serialize()
        rdfbuffer = StringIO()
        rdfbuffer.write(rdftext)

        # Initialize the attachments descriptor object
        attachments = [{
            'file_buffer': rdfbuffer,
            'name': "patient.xml",
            'mime': "text/xml"
        }, {
            'file_buffer': manifestbuffer,
            'name': "manifest.json",
            'mime': "text/xml"
        }]

        # Initialize the mailer settings
        settings = {
            'host': SMTP_HOST_ALT,
            'user': SMTP_USER_ALT,
            'password': SMTP_PASS_ALT
        }

        # Send the SMART Direct message
        send_message(me, you, subject, message, message, attachments, settings)

        # Clean up the string buffers
        manifestbuffer.close()
        rdfbuffer.close()

        # Respond with success message
        return json.dumps({'result': 'ok'})