...
Plantumlcloud | ||||||||
---|---|---|---|---|---|---|---|---|
|
Testing
Testing the WebSocket from JavaScript console
The following JavaScript code could be executed from your browser developer tools console.
Code Block | ||
---|---|---|
| ||
var msg = {
type: "claim.bundle.payload",
content: `{
"resourceType": "Bundle",
"entry": [
{
"fullUrl": "http://127.0.0.1:8001/api_fhir_r4/Claim/FCD34CB1-2630-4E21-88EE-C38521C09F0D",
"resource": {
"resourceType": "Claim",
"billablePeriod": {
"end": "2016-05-16",
"start": "2016-05-16"
},
"created": "2016-05-16",
"diagnosis": [
{
"diagnosisReference": {
"identifier": 5367,
"reference": "Condition/5367",
"type": "Condition"
},
"sequence": 1,
"type": [
{
"coding": [
{
"code": "icd_0"
}
]
}
]
}
],
"enterer": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "73371CFC-9C4D-4F71-B64E-6C858E0B9876"
},
"reference": "Practitioner/73371CFC-9C4D-4F71-B64E-6C858E0B9876",
"type": "Practitioner"
},
"facility": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "36ECB0DB-E942-4A2D-A0C5-33ED4D00419D"
},
"reference": "P7101752/36ECB0DB-E942-4A2D-A0C5-33ED4D00419D",
"type": "P7101752"
},
"id": "FCD34CB1-2630-4E21-88EE-C38521C09F0D",
"identifier": [
{
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "FCD34CB1-2630-4E21-88EE-C38521C09F0D"
},
{
"type": {
"coding": [
{
"code": "MR"
}
]
},
"use": "usual",
"value": "601"
}
],
"insurance": [
{
"coverage": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "8B18153E-2A42-4AEA-85B8-8603E89928B8"
},
"reference": "Coverage/8B18153E-2A42-4AEA-85B8-8603E89928B8",
"type": "Coverage"
},
"focal": true,
"sequence": 0
}
],
"item": [
{
"category": {
"text": "service"
},
"extension": [
{
"url": "ActivityDefinition",
"valueReference": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "5b9e5be3-6da1-40eb-b4a0-6588122e5f53"
},
"reference": "ActivityDefinition/5b9e5be3-6da1-40eb-b4a0-6588122e5f53",
"type": "ActivityDefinition"
}
}
],
"productOrService": {
"text": "OPD 1"
},
"quantity": {
"value": 1.0
},
"sequence": 1,
"unitPrice": {
"currency": "$",
"value": 80.0
}
}
],
"patient": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "39418469-FC67-4363-BB51-B59B19FDBB47"
},
"reference": "92260E4F/39418469-FC67-4363-BB51-B59B19FDBB47",
"type": "92260E4F"
},
"priority": {
"coding": [
{
"code": "normal"
}
]
},
"provider": {
"identifier": {
"type": {
"coding": [
{
"code": "UUID"
}
]
},
"use": "usual",
"value": "73371CFC-9C4D-4F71-B64E-6C858E0B9876"
},
"reference": "PractitionerRole/73371CFC-9C4D-4F71-B64E-6C858E0B9876",
"type": "PractitionerRole"
},
"status": "active",
"total": {
"currency": "$",
"value": 80.0
},
"type": {
"text": "O"
},
"use": "claim"
}
}
],
"total": 531900,
"type": "searchset"
}`
};
const ENCODING = 'utf-8';
var ws = new WebSocket('ws://localhost:8001/claim_ai/ws/Claim/process1/');
ws.binaryType = 'arraybuffer';
ws.onmessage = event => {
let str = '';
if (typeof event.data === "string") {
str = event.data;
} else {
str = new TextDecoder(ENCODING).decode(event.data);
}
let json = JSON.parse(str);
console.log('received', json);
};
ws.onopen = () => {
let json = msg,
str = JSON.stringify(json);
console.log('sent',json);
ws.send(new TextEncoder(ENCODING).encode(str));
} |