Data Structures in D3 - d3.js

A group project of mine are struggling with a data structure, after having been told that it was initially wrong.
Alcohol consumption is the percentage of those who are on the mental health register in that particular city, so it should be a child element of mental health. To me, this looks right, but is producing no output in d3, only England, North England, Bradford City, Mental Health, and Alcohol Consumption produce an output, but not for Leeds. More data will be added, we just needed to get the structure correct.
var data = {
"name": "England",
"children": [
{
"name": "North England",
"children": [
{
"name": "Bradford City",
"children": [
{
"name": "Mental Health",
"value": 1.22,
"children": [
{
"name": "Alcohol Consumption",
"value": 70.23,
}
]
}
],
"name": "Leeds",
"children": [
{
"name": "Mental Health",
"value": 1.22,
"children": [
{
"name": "Alcohol Consumption",
"value": 70.23,
}
]
}
]
}
]
}
]
};

This is the right structure:
var data = {
"name": "England",
"children": [{
"name": "North England",
"children": [{
"name": "Bradford City",
"children": [{
"name": "Mental Health",
"value": 1.22,
"children": [{
"name": "Alcohol Consumption",
"value": 70.23,
}]
}]
}, {
"name": "Leeds",
"children": [{
"name": "Mental Health",
"value": 1.22,
"children": [{
"name": "Alcohol Consumption",
"value": 70.23,
}]
}]
}]
}]
};
The children for North England should be a list of objects.

Related

Add extension to R4 Patient

How do I add the below to an R4 Patient?
"search": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/match-grade",
"valueCode": "certain"
}
],
"mode": "match",
"score": 1.0
}
The objects that were under stu2 and stu3 (I think) have been deprecated.
DSTU3 and Later
// Create an example patient
Patient patient = new Patient();
patient.addIdentifier().setUse(Identifier.IdentifierUse.OFFICIAL).setSystem("urn:example").setValue("7000135");
// Create an extension
Extension ext = new Extension();
ext.setUrl("http://example.com/extensions#someext");
ext.setValue(new DateTimeType("2011-01-02T11:13:15"));
// Add the extension to the resource
patient.addExtension(ext);
Full "response" json from patient match below (sample data, not real data !! )
{
"resourceType": "Bundle",
"id": "94897c77-4120-482f-bdb4-4c8b9a71ade1",
"meta": {
"versionId": "1",
"lastUpdated": "2020-11-24T08:45:49.445-05:00"
},
"type": "searchset",
"total": 1,
"link": [
{
"relation": "self",
"url": "http://wildfhir4.aegis.net/fhir4-0-0/Patient/$match?"
}
],
"entry": [
{
"fullUrl": "http://wildfhir4.aegis.net/fhir4-0-0/Patient/9126db824dcf4d5ab3f68e63bd5eaced",
"resource": {
"resourceType": "Patient",
"id": "9126db824dcf4d5ab3f68e63bd5eaced",
"meta": {
"versionId": "1",
"lastUpdated": "2020-09-03T09:03:28.193-04:00",
"tag": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-ActReason",
"code": "HTEST",
"display": "test health data"
}
]
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><table><tbody><tr><td>Name</td><td>Peter James \n <b>Chalmers</b> ("Jim") \n </td></tr><tr><td>Address</td><td>534 Erewhon, Pleasantville, Vic, 3999</td></tr><tr><td>Contacts</td><td>Home: unknown. Work: (03) 5555 6473</td></tr><tr><td>Id</td><td>MRN: 12345 (Acme Healthcare)</td></tr></tbody></table></div>"
},
"identifier": [
{
"use": "usual",
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "MR"
}
]
},
"system": "urn:oid:1.2.36.146.595.217.0.1",
"value": "12345",
"period": {
"start": "2001-05-06"
},
"assigner": {
"display": "Acme Healthcare"
}
}
],
"active": true,
"name": [
{
"use": "official",
"family": "Chalmers",
"given": [
"Peter",
"James"
]
},
{
"use": "usual",
"given": [
"Jim"
]
},
{
"use": "maiden",
"family": "Windsor",
"given": [
"Peter",
"James"
],
"period": {
"end": "2002"
}
}
],
"telecom": [
{
"use": "home"
},
{
"system": "phone",
"value": "(03) 5555 6473",
"use": "work",
"rank": 1
},
{
"system": "phone",
"value": "(03) 3410 5613",
"use": "mobile",
"rank": 2
},
{
"system": "phone",
"value": "(03) 5555 8834",
"use": "old",
"period": {
"end": "2014"
}
}
],
"gender": "male",
"birthDate": "1974-12-25",
"_birthDate": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
"valueDateTime": "1974-12-25T14:35:45-05:00"
}
]
},
"deceasedBoolean": false,
"address": [
{
"use": "home",
"type": "both",
"text": "534 Erewhon St PeasantVille, Rainbow, Vic 3999",
"line": [
"534 Erewhon St"
],
"city": "PleasantVille",
"district": "Rainbow",
"state": "Vic",
"postalCode": "3999",
"period": {
"start": "1974-12-25"
}
}
],
"contact": [
{
"relationship": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0131",
"code": "N"
}
]
}
],
"name": {
"family": "du Marché",
"_family": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/humanname-own-prefix",
"valueString": "VV"
}
]
},
"given": [
"Bénédicte"
]
},
"telecom": [
{
"system": "phone",
"value": "+33 (237) 998327"
}
],
"address": {
"use": "home",
"type": "both",
"line": [
"534 Erewhon St"
],
"city": "PleasantVille",
"district": "Rainbow",
"state": "Vic",
"postalCode": "3999",
"period": {
"start": "1974-12-25"
}
},
"gender": "female",
"period": {
"start": "2012"
}
}
],
"managingOrganization": {
"reference": "Organization/1"
}
},
"search": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/match-grade",
"valueCode": "certain"
}
],
"mode": "match",
"score": 1.0
}
}
]
}
APPEND: I found this:
https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-r4/org/hl7/fhir/r4/model/codesystems/MatchGrade.html
That extension isn't allowed on Patient. It's defined with a context of Bundle.entry.search. It's not a characteristic of the patient themselves, it's a characteristic of a particular entry in a search result based on a specific set of search criteria. The same Patient instance might well be a good result on one search and a poor result on a different search. So to add the extension, you'd have to add it on a 'search' object, not patient.
Ok.
Here it is. The primary objects were inner/nested objects under Bundle....thus why I didn't see them early. (example : Bundle.BundleEntrySearchComponent)
// a java example with the import statements. #shocking!
//import org.hl7.fhir.r4.model.Bundle;
//import org.hl7.fhir.r4.model.CodeType;
//import org.hl7.fhir.r4.model.Extension;
//import org.hl7.fhir.r4.model.Patient;
//import org.hl7.fhir.r4.model.codesystems.MatchGrade;
//import java.util.Collections;
Bundle innerBundle = new Bundle();
innerBundle.setType(Bundle.BundleType.SEARCHSET);
innerBundle.setTotal(1);
Patient pat = new Patient();
HumanName hn = new HumanName();
hn.setFamily("Smith");
p.setName(Collections.singletonList(hn));
Bundle.BundleEntrySearchComponent besc = new Bundle.BundleEntrySearchComponent();
besc.setScore(0.88);
besc.setMode(Bundle.SearchEntryMode.MATCH);
Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
Extension matchGradeExtension = besc.addExtension();
matchGradeExtension.setUrl("http://hl7.org/fhir/StructureDefinition/match-grade");
matchGradeExtension.setValue(new CodeType(MatchGrade.PROBABLE.toCode()));
bec.setResource(pat);
bec.setSearch(besc);
innerBundle.setEntry(Collections.singletonList(bec));
Json looks like this:
{
"resourceType": "Bundle",
"type": "searchset",
"total": 1,
"entry": [
{
"resource": {
"resourceType": "Patient",
"name": [
{
"family": "Smith"
}
]
},
"search": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/match-grade",
"valueCode": "certain"
}
],
"mode": "match",
"score": 0.88
}
}
]
}

amcharts - Force Directed Tree - convert data Laravel PHP

I am trying to display a force directed tree. There are 3 models
Company / Division / Department
Each Company has many divisions. Each division belongs to one Company.
Each Division has many departments. Each department belongs to one Division.
amcharts expects a syntax like:
[{
"name": "First",
"children": [{
"name": "A1", "value": 100
}, {
"name": "A2", "value": 60
}, {
"name": "A3", "value": 30
}]
}, {
"name": "Second",
"children": [{
"name": "B1", "value": 135
}, {
"name": "B2", "value": 98
}, {
"name": "B3", "value": 56
}]
}, {
"name": "Third",
"children": [{
"name": "C1", "value": 335
}, {
"name": "C2", "value": 148
}, {
"name": "C3", "value": 126
}, {
"name": "C4", "value": 26
}]
}, {
"name": "Fourth",
"children": [{
"name": "D1", "value": 415
}, {
"name": "D2", "value": 148
}, {
"name": "D3", "value": 89
}, {
"name": "D4", "value": 64
}, {
"name": "D5", "value": 16
}]
}, {
"name": "Fifth",
"children": [{
"name": "E1", "value": 687
}, {
"name": "E2", "value": 148
}]
}]
I am only able to get the first level here:
foreach ($companies as $company) {
$data[] =
(object) [
'name' => $company->name,
'value' => $company->value,
];
}
I am sure that I need to further iterate through $company->devisions and so on but not sure how to build the final construct amcharts is expecting. Any hints?
You can try something in the lines of:
$data = [];
foreach ($companies as $company) {
$childrenArray = [
'name' => $company->name,
];
foreach ($company->divisions as $division) {
$childArray['children'][] = [
'name' => $division->name,
'value' => $division->value,
];
}
$data[] = $childrenArray;
}
return json_encode($data);

No signature of method: org.apache.jmeter.threads.JMeterVariables.put() is applicable for argument types: (java.lang.String, java.lang.Integer)

I have a Sample JSON response as below:
{
"id": 37,
"merchant_id": "39",
"title": "Parker Pens",
"subtitle": null,
"price": 1000,
"description": null,
"images": [],
"image_thumbs": [],
"options": [{
"code": "color",
"label": "Color",
"extra_info": "",
"values": [{
"label": "Red",
"value": "8"
}, {
"label": "Yellow",
"value": "9"
}, {
"label": "Pink",
"value": "10"
}]
}, {
"code": "size",
"label": "Size",
"extra_info": "",
"values": [{
"label": "Small",
"value": "4"
}, {
"label": "Medium",
"value": "5"
}, {
"label": "Large",
"value": "6"
}]
}],
"options_available": [{
"combination": [{
"code": "color",
"value": "Red"
}, {
"code": "size",
"value": "Small"
}]
}, {
"combination": [{
"code": "color",
"value": "Red"
}, {
"code": "size",
"value": "Medium"
}]
}, {
"combination": [{
"code": "color",
"value": "Red"
}, {
"code": "size",
"value": "Large"
}]
}, {
"combination": [{
"code": "color",
"value": "Yellow"
}, {
"code": "size",
"value": "Small"
}]
}, {
"combination": [{
"code": "color",
"value": "Yellow"
}, {
"code": "size",
"value": "Medium"
}]
}, {
"combination": [{
"code": "color",
"value": "Yellow"
}, {
"code": "size",
"value": "Large"
}]
}, {
"combination": [{
"code": "color",
"value": "Pink"
}, {
"code": "size",
"value": "Small"
}]
}, {
"combination": [{
"code": "color",
"value": "Pink"
}, {
"code": "size",
"value": "Medium"
}]
}, {
"combination": [{
"code": "color",
"value": "Pink"
}, {
"code": "size",
"value": "Large"
}]
}],
"custom_options": []
}
and i have my Sampler as
import org.json.JSONObject;
import org.json.JSONArray;
String response= prev.getResponseDataAsString();
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("options");
Integer count= jsonArray.length();
vars.put('counts', count);
But while running the script I'm getting an error:
No signature of method: org.apache.jmeter.threads.JMeterVariables.put() is applicable for argument types: (java.lang.String, java.lang.Integer)
In addition to values also (Counts=2). My intention is to get the count of array in "Options" Key ( See response above)
vars.put doesn't support different value than regular String and you are trying to put Integer value.
Easy way out by simple convert:
vars.put("counts", Integer.toString(count));
Another option is save object as is using vars.putObject
vars.putObject("counts", count);
Also move to JSR223 Sampler, per JMeter best practices:
Since JMeter 3.1, we advise switching from BeanShell to JSR223 Test Elements
Go for JSR223 PostProcessor and Groovy language as:
Groovy performance is much better comparing to Beanshell
Groovy has built-in JSON support
Groovy provides a lot of enhancements on top of Java SDK
Groovy equivalent of your 7 lines of Beanshell code would be:
vars.put('counts',new groovy.json.JsonSlurper().parse(prev.getResponseData()).options.size() as String)

When connecting to LUIS, what does the "forceset" parameter do

In my LUIS app I have an intent called GetWeather requiring a Location to be set.
When connecting to the app using the query
What is the weather in london
it correctly returns
{
"query": "what is the weather in london",
"topScoringIntent": {
"intent": "GetWeather",
"score": 0.999875546,
"actions": [
{
"triggered": true,
"name": "GetWeather",
"parameters": [
{
"name": "Location",
"type": "Location",
"required": true,
"value": [
{
"entity": "london",
"type": "Location",
"resolution": {}
}
]
}
]
}
]
},
"entities": [
{
"entity": "london",
"type": "Location",
"startIndex": 23,
"endIndex": 28,
"score": 0.832388461,
"resolution": {}
}
],
"dialog": {
"contextId": "e1df6c2d-e691-4fc6-89f2-3ee2ef519724",
"status": "Finished"
}
}
If I instead use the query
What is the weather
It returns the following expected result.
{
"query": "what is the weather",
"topScoringIntent": {
"intent": "GetWeather",
"score": 1.0,
"actions": [
{
"triggered": false,
"name": "GetWeather",
"parameters": [
{
"name": "Location",
"type": "Location",
"required": true,
"value": null
}
]
}
]
},
"entities": [],
"dialog": {
"prompt": "Where",
"parameterName": "Location",
"parameterType": "Location",
"contextId": "3b0725f4-7d6f-43fd-ab6e-02fc11c3eed1",
"status": "Question"
}
}
I thought that using the contextID together with the forceSet parameter in my next call would set the parameter Location to whatever I send as the query. The conection string I use is this:
https://api.projectoxford.ai/luis/v2.0/apps/{APP_ID}?subscription-key={SUBSCRIPTION_KEY}&q=london&contextid=3b0725f4-7d6f-43fd-ab6e-02fc11c3eed1&forceset=Location
Instead I get the following response back:
{
"query": "london",
"topScoringIntent": {
"intent": "GetWeather",
"score": 1.0,
"actions": [
{
"triggered": false,
"name": "GetWeather",
"parameters": [
{
"name": "Location",
"type": "Location",
"required": true,
"value": null
}
]
}
]
},
"entities": [],
"dialog": {
"prompt": "Where",
"parameterName": "Location",
"parameterType": "Location",
"contextId": "3b0725f4-7d6f-43fd-ab6e-02fc11c3eed1",
"status": "Question"
}
}
I had expected to get something like my first response back.
Am I doing something wrong or just misunderstanding what the forceSet parameter is supposed to do?

How to merge two trees in golang ?

The tree struct is below:
type TreeData struct {
Name string `json:"name"`
Depth int `json:"depth"`
Children []TreeData `json:"children"`
}
I have two trees, and I want merge them into one tree.
How can I do that?
If someone could show me your code, I would be very appreciate!!
I wonder if I could use the recursion way to finish the merge?
treeone:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "dev",
"depth": 4,
"children": null
}
]
}
]
}
]
}
treetwo:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "influxdb",
"depth": 4,
"children": [
{
"name": "cluster-one"
"depth": 5
"children": null
}
]
}
]
}
]
}
]
}
merge:
{
"name": ".",
"depth": 1,
"children": [
{
"name": "com",
"depth": 2,
"children": [
{
"name": "didi"
"depth": 3,
"children": [
{
"name": "influxdb",
"depth": 4,
"children": [
{
"name": "cluster-one"
"depth": 5
"children": null
}
]
},
{
"name": "dev",
"depth": 4,
"children": null
}
]
}
]
}
]
}
I find a good solution for golang to create a tree!!
http://blog.csdn.net/xtxy/article/details/50812392

Resources