Visual is to get this working in mkdocs driven by a local AJAX server.
This one is hard to give an example to but I will. Before I do that, the problem is that I want to use various ajax endpoints to drive Vega visuals in MkDocs. But I run into the CORS permissions.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://machine1:8080/dataflare. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.
I have struggled to find documentation on how to solve this so, does anyone know how do we enable this in mkdocs?
The sample is long but this works until you use a local data source other than the vega data. When you change the AJAX endpoint from "url": "https://vega.github.io/vega/data/flare.json" to http://myhost:8080/shortflare (or fullflare endpoint) you get the CORS permission error above.
So should the client mkdocs enable the endpoint as safe cross site source or should bottle AJAX be sending a CORS header? I dont understand why the original AJAX works when the bottle endpoint does not work.
Now the hard part. Showing an example.
This simple bottle server will be the AJAX endpoint mimic of the original flaredata :
sample of data is on http://myhost:8080/shortflare
full dataset http://myhost:8080/fullflare is served via proxy from https://vega.github.io/vega/data/flare.json
from bottle import route, run, template
import requests
DATAFLARE = '''
[
{
"id": 1,
"name": "flare"
},
{
"id": 2,
"name": "analytics",
"parent": 1
},
{
"id": 3,
"name": "cluster",
"parent": 2
},
{
"id": 4,
"name": "AgglomerativeCluster",
"parent": 3,
"size": 3938
}
]
'''
#route('/shortflare')
def getflare():
return DATAFLARE
#route('/fullflare')
def proxyflare():
return requests.get('https://vega.github.io/vega/data/flare.json').text
if __name__ == "__main__":
run(host='0.0.0.0', port=8080, debug=True)
mkdocs setup (i.e mkdocs.yml)
site_name: VEGA
dev_addr: '0.0.0.0:2001'
theme:
name: material
nav_style: dark
palette:
accent: pink
primary: lime
plugins:
- search
- charts
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: vegalite
class: vegalite
format: !!python/name:mkdocs_charts_plugin.fences.fence_vegalite
extra_javascript:
- https://cdn.jsdelivr.net/npm/vega#5
- https://cdn.jsdelivr.net/npm/vega-lite#5
- https://cdn.jsdelivr.net/npm/vega-embed#6
ve requires
mkdocs==1.2.3
mkdocs-charts-plugin==0.0.6
mkdocs-material==7.3.6
and the markdown to make the vegalite graphic (add this in index.md or anywhere)
Relational maps.
```vegalite
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "An example of Cartesian layouts for a node-link diagram of hierarchical data.",
"width": 600,
"height": 1600,
"padding": 5,
"signals": [
{
"name": "labels", "value": true,
"bind": {"input": "checkbox"}
},
{
"name": "layout", "value": "tidy",
"bind": {"input": "radio", "options": ["tidy", "cluster"]}
},
{
"name": "links", "value": "diagonal",
"bind": {
"input": "select",
"options": ["line", "curve", "diagonal", "orthogonal"]
}
},
{
"name": "separation", "value": false,
"bind": {"input": "checkbox"}
}
],
"data": [
{
"name": "tree",
"url": "https://vega.github.io/vega/data/flare.json",
"transform": [
{
"type": "stratify",
"key": "id",
"parentKey": "parent"
},
{
"type": "tree",
"method": {"signal": "layout"},
"size": [{"signal": "height"}, {"signal": "width - 100"}],
"separation": {"signal": "separation"},
"as": ["y", "x", "depth", "children"]
}
]
},
{
"name": "links",
"source": "tree",
"transform": [
{ "type": "treelinks" },
{
"type": "linkpath",
"orient": "horizontal",
"shape": {"signal": "links"}
}
]
}
],
"scales": [
{
"name": "color",
"type": "linear",
"range": {"scheme": "magma"},
"domain": {"data": "tree", "field": "depth"},
"zero": true
}
],
"marks": [
{
"type": "path",
"from": {"data": "links"},
"encode": {
"update": {
"path": {"field": "path"},
"stroke": {"value": "#ccc"}
}
}
},
{
"type": "symbol",
"from": {"data": "tree"},
"encode": {
"enter": {
"size": {"value": 100},
"stroke": {"value": "#fff"}
},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"fill": {"scale": "color", "field": "depth"}
}
}
},
{
"type": "text",
"from": {"data": "tree"},
"encode": {
"enter": {
"text": {"field": "name"},
"fontSize": {"value": 9},
"baseline": {"value": "middle"}
},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"dx": {"signal": "datum.children ? -7 : 7"},
"align": {"signal": "datum.children ? 'right' : 'left'"},
"opacity": {"signal": "labels ? 1 : 0"}
}
}
}
]
}
```
I actually found out why. The bottle server would need to send the proper header. This is done by adding these few lines to the bottle server.
from bottle_cors_plugin import cors_plugin
from bottle import app
app = app()
app.install(cors_plugin('*'))
if __name__ == "__main__":
run(app=app, host='0.0.0.0', port=8080, debug=True)
Related
I have a payload for Claim.
I want to add an additional field LOB (Line of business) using extension, and POST it to FHIR Server, and then search the resource using that field like:
GET: http://fhir_server/Claim?lob=value
In the payload I have added the extension block:
{
"resourceType": "Claim",
"status": "active",
"extension" : [{
"url" : "<i entered some random url>",
"valueString" : "MAPD"
}],
"identifier": [{
"value": "TEST"
}],
"type": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/claim-type",
"code": "institutional"
}]
},
"use": "claim",
"patient": {
"reference": "f8d8477c-1ef4-4878-abed-51e514bfd91f",
"display": "John_Smith"
},
"billablePeriod": {
"start": "1957-04-12T21:08:35+05:30",
"end": "1957-04-12T21:23:35+05:30"
},
"created": "1957-04-12T21:23:35+05:30",
"provider": {
"reference": "urn:uuid:Organization",
"display": "PCP79032"
},
"priority": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/processpriority",
"code": "normal"
}]
},
"facility": {
"reference": "Location",
"display": "PCP79032"
},
"diagnosis": [{
"sequence": 1,
"diagnosisReference": {
"reference": "0316a0c4-0e46-e3fa-a7bf-9e4f3b9c9e92"
}
}, {
"sequence": 2,
"diagnosisReference": {
"reference": "932432b0-ac67-0f7a-1382-26c48050c62f"
}
}],
"insurance": [{
"sequence": 1,
"focal": true,
"coverage": {
"display": "Blue Cross Blue Shield"
}
}],
"item": [{
"sequence": 1,
"productOrService": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "162673000",
"display": "General examination of patient (procedure)"
}],
"text": "General examination of patient (procedure)"
},
"encounter": [{
"reference": "67062d00-2531-3ebd-8558-1de2fd3e5aab"
}]
}, {
"sequence": 2,
"diagnosisSequence": [1],
"productOrService": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "713458007",
"display": "Lack of access to transportation (finding)"
}],
"text": "Lack of access to transportation (finding)"
}
}, {
"sequence": 3,
"diagnosisSequence": [2],
"productOrService": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "73595000",
"display": "Stress (finding)"
}],
"text": "Stress (finding)"
}
}],
"total": {
"value": 786.3299999999999,
"currency": "USD"
}
}
and created a SearchParameter using POST:
{
"resourceType" : "SearchParameter",
"id": "21761828-b929-416a-8813-d3646cf288f4",
"name": "lob",
"status": "active",
"url" : "https://fhir_server/StructureDefinition/f971fc4998167948838f8a8831ea914c",
"description": "Returns a Claim with extension.valueString matching the specified one in request.",
"code" : "lob",
"base" : [ "Claim" ],
"type" : "string",
"expression": "Claim.extension.where(url ='https://fhir_server/StructureDefinition/f971fc4998167948838f8a8831ea914c').value.string"
}
but while fetching the result (GET: https://fhirserver/Claim?lob=MAPD), I am getting the full dataset instead of the filtered result.
I also did a $reindex on the /Claim/<resource_id>/$reindex, but its not listing the field lob.
Am I missing something ?
Servers need to be configured to support new search parameters - you can't search by arbitrary elements, only by specific SearchParameters the server supports. That's true for both searching on extensions as well as core elements. You'll have to work with the owner of the server to support your desired search capability. Did you try posting on http://chat.fhir.org to find out if there was a non-extension mechanism to represent "line of business" on a Claim?
I found an interesting article that used several data models on Vega-Lite. Tabular data were combined by key like in relational databases.
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"title": "Test",
"datasets": {
"stores": [
{"cmdb_id1": 1, "group": "type1"},
{"cmdb_id1": 2, "group": "type1"},
{"cmdb_id1": 3, "group": "type2"}
],
"labelsTimelines": [
{"cmdb_id2": 1, "value": 83},
{"cmdb_id2": 2, "value": 53},
{"cmdb_id2": 3, "value": 23}
]
},
"data": {"name": "stores"},
"transform": [
{
"lookup": "cmdb_id1",
"from": {
"data": {"name": "labelsTimelines"},
"key": "cmdb_id2",
"fields": ["value"]
}
}
],
"mark": "bar",
"encoding": {
"y": {"aggregate": "sum", "field": "value", "type": "quantitative"},
"x": {"field": "group", "type": "ordinal"}
}
}
Vega Editor
The question arose as to whether it was possible to obtain the same result using the construction:
"data": {"url": "...."}
Changed the source for Elasticsearch query:
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"datasets": {
"stores": [{
"url": {
"%context%": "true"
"index": "test_cmdb"
"body": {
"size": 1000,
"_source": ["cmdb_id", "street","group"]
}
}
format: {property: "hits.hits"}
}]}
"data": {
"name": "stores"
},
"encoding": {
"x": {"field": "url.body.size", "type": "ordinal", "title": "X"},
"y": {"field": "url.body.size", "type": "ordinal", "title": "Y"}
},
"layer": [
{
"mark": "rect",
"encoding": {
"tooltip": [
{"field": "url"}]
}
}
]
}
I understand that there is a syntactical error, the data did not come from Elasticsearch.
Thanks in advance!
example.png
No, it is not currently possible to specify URL data within top-level "datasets". The relevant open feature request in Vega-Lite is here: https://github.com/vega/vega-lite/issues/4004.
Your much better off using Vega rather than Vega-lite for this. In Vega you can specify as many datasets as you like with a URL. For example...
...
data: [
{
name: dataset_1
url: {
...
}
}
{
name: dataset_2
url: {
...
}
}
]
...
This can actually get very interesting since it means you can combine data from multiple indices into one visualisation.
I know this is late, but figured this might help people who are looking around.
I'm using the Google Plus API, and there seems to be no information in the JSON response regarding the collection of the post. I was wondering if there was a way to access which collection a post belongs using the API data.
For example, could we use the URL given to parse the collection from the webpage? Does anyone have any idea how this could be done in a performant way?
The google+ api is a read only api and every limited it gives you access to people, activities and comments.
Activites list returns a list of all activities#resource posts by a user. try it
The only collection you can send is public. the response looks like this.
{
"kind": "plus#activity",
"etag": "\"RKS4-q7QGL10FxltAebpjqjKQR0/82jivrLU7ubQ-fwlLaXGSt3krb8\"",
"title": "",
"published": "2018-06-18T07:03:54.034Z",
"updated": "2018-06-18T07:03:54.034Z",
"id": "z13lu3vowpa5x3aws04chl2brzavs1rplos0k",
"url": "https://plus.google.com/+LindaLawton/posts/STgianNMQwU",
"actor": {
"id": "117200475532672775346",
"displayName": "Linda Lawton",
"url": "https://plus.google.com/117200475532672775346",
"image": {
"url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAl1I/UcwPajZOuN4/photo.jpg?sz=50"
},
"verification": {
"adHocVerified": "UNKNOWN_VERIFICATION_STATUS"
}
},
"verb": "post",
"object": {
"objectType": "note",
"actor": {
"verification": {
"adHocVerified": "UNKNOWN_VERIFICATION_STATUS"
}
},
"content": "",
"url": "https://plus.google.com/+LindaLawton/posts/STgianNMQwU",
"replies": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/comments"
},
"plusoners": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/people/plusoners"
},
"resharers": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/people/resharers"
},
"attachments": [
{
"objectType": "article",
"displayName": "leastprivilege/AspNetCoreSecuritySamples",
"content": "AspNetCoreSecuritySamples - Samples for various ASP.NET Core Security Features",
"url": "https://github.com/leastprivilege/AspNetCoreSecuritySamples",
"image": {
"url": "https://lh3.googleusercontent.com/proxy/1pdxjC-TsuF0-8yHOZKvfDOXG1pNWAIemDoW7OzrFy8pcckGqr0BTJj-TwgW9KgEuoGLJjfUKLWSCouJwTT7FjoOmZ_xURQwzz4=w506-h910",
"type": "image/jpeg",
"height": 910,
"width": 506
},
"fullImage": {
"url": "https://avatars0.githubusercontent.com/u/1454075?s=400&v=4",
"type": "image/jpeg"
}
}
]
},
"provider": {
"title": "Google+"
},
"access": {
"kind": "plus#acl",
"description": "Public",
"items": [
{
"type": "public"
}
]
}
},
the above post here is actually within one of my collections. But no were in the response does it mention the id of the collection that its in which is olLcVE
As i mentioned this is a very limited api and what you want to do is not available.
When using the sample POSTMAN request:
{
"idempotency_key": "74ae1696-b1e3-4328-af6d-f1e04d947a13",
"order": {
"reference_id": "my-order-001",
"line_items": [
{
"name": "line-item-1",
"quantity": "1",
"base_price_money": {
"amount": 1599,
"currency": "USD"
}
},
{
"name": "line-item-2",
"quantity": "2",
"base_price_money": {
"amount": 799,
"currency": "USD"
}
}]
},
"ask_for_shipping_address": true,
"merchant_support_email": "merchant+support#website.com",
"pre_populate_buyer_email": "buyer#email.com",
"pre_populate_shipping_address": {
"address_line_1": "500 Electric Ave",
"address_line_2": "Suite 600",
"locality": "New York",
"administrative_district_level_1": "NY",
"postal_code": "10003",
"first_name": "Jane",
"last_name": "Doe"
},
"redirect_url": "https://merchant.website.com/order-confirm"
}
I'm getting the following response:
{
"errors": [
{
"category": "INVALID_REQUEST_ERROR",
"code": "INVALID_VALUE",
"detail": "The order must have at least one line item.",
"field": "line_items"
}]
}
This is simply executing the sample POSTMAN requests available via https://docs.connect.squareup.com/api/connect/v2/#runningpostman
I was having the same issue and I reached out to Tristan. Tristan replied there was a bug that square development had to fix. I confirmed that the create checkout API is now working properly so this issue should be resolved now.
Are you using your sandbox or production access tokens? I was able to generate a checkout form with the example postman request:
{
"idempotency_key": "73ae1696-b1e3-4328-af6d-f1e04d947a13",
"order": {
"reference_id": "my-order-001",
"line_items": [
{
"name": "line-item-1",
"quantity": "1",
"base_price_money": {
"amount": 1599,
"currency": "USD"
}
},
{
"name": "line-item-2",
"quantity": "2",
"base_price_money": {
"amount": 799,
"currency": "USD"
}
}
]
},
"ask_for_shipping_address": true,
"merchant_support_email": "merchant+support#website.com",
"pre_populate_buyer_email": "buyer#email.com",
"pre_populate_shipping_address": {
"address_line_1": "500 Electric Ave",
"address_line_2": "Suite 600",
"locality": "New York",
"administrative_district_level_1": "NY",
"postal_code": "10003",
"first_name": "Jane",
"last_name": "Doe"
},
"redirect_url": "https://merchant.website.com/order-confirm"
}
I am writing a wrapper to retrive transaction data for the Square Connect API V2. I am able to retrive the trasactions with Order data missing.
I am getting following response using All Transaction and Retrieve Transaction API:
{
"transactions": [
{
"id": "mYziFkYv2QK7e2kb2vyIhegeV",
"location_id": "75S3K9Z9KSVYK",
"created_at": "2017-04-17T11:00:51Z",
"tenders": [
{
"id": "2qeDw6CmCs299m9w0RY7KQB",
"location_id": "75S3K9Z9KSVYK",
"transaction_id": "mYziFkYv2QK7e2kb2vyIhegeV",
"created_at": "2017-04-17T11:00:51Z",
"amount_money": {
"amount": 10000,
"currency": "INR"
},
"processing_fee_money": {
"amount": 0,
"currency": "INR"
},
"type": "OTHER"
}
],
"product": "REGISTER",
"client_id": "75S3K9Z9KSVYK-a776-4377-84f5-75S3K9Z9KSVYK"
},
{
"id": "UJsg9IdIv9WWvqT1h2VkbxgeV",
"location_id": "75S3K9Z9KSVYK",
"created_at": "2017-04-17T11:00:37Z",
"tenders": [
{
"id": "UVuQghb8RTF8OUcmAsaXKQB",
"location_id": "75S3K9Z9KSVYK",
"transaction_id": "UJsg9IdIv9WWvqT1h2VkbxgeV",
"created_at": "2017-04-17T11:00:37Z",
"amount_money": {
"amount": 0,
"currency": "INR"
},
"processing_fee_money": {
"amount": 0,
"currency": "INR"
},
"type": "NO_SALE"
}
],
"product": "REGISTER",
"client_id": "75S3K9Z9KSVYK-a751-4434-a041-75S3K9Z9KSVYK"
}
]}
Is there any way to get order (line item) details?
If you are looking for itemizations, you can use the v1 transactions endpoints.
See here: https://docs.connect.squareup.com/api/connect/v1/#get-paymentid