How to display 0 if no record in laravel - laravel

I have this query. Currently, this displays the status_count for the logged users. I want to update this query to display all the statuses from the status table and if the logged user has no record for any statuses to display status_count as 0.
$orderStatistics = OrderHeader::select('status.id', 'status.name', 'status.description', 'status.type', 'status.code',
DB::raw('order_status,count(*) as status_count'))
->leftjoin('status', 'status.code', '=', 'order_header.order_status')
->orderBy('status.id')
->groupBy('order_status')
->where([['order_header.user_id', auth()->user()->id], ['status.type', 'ORD']])
->get();
Let's say the status table has one new record TST where type is equal to ORD. And order_header table does not contain any record for TST for the currently logged user.
Current Response:
"data": [
{
"id": 11,
"name": "note",
"description": "note",
"type": "ORD",
"code": "NTE",
"order_status": "NTE",
"status_count": 2
},
{
"id": 12,
"name": "approved",
"description": "approved",
"type": "ORD",
"code": "APR",
"order_status": "APR",
"status_count": 2
},
]
How I want is:
"data": [
{
"id": 11,
"name": "note",
"description": "note",
"type": "ORD",
"code": "NTE",
"order_status": "NTE",
"status_count": 2
},
{
"id": 12,
"name": "approved",
"description": "approved",
"type": "ORD",
"code": "APR",
"order_status": "APR",
"status_count": 2
},
{
"id": 13,
"name": "test",
"description": "test",
"type": "ORD",
"code": "TST",
"order_status": "TST",
"status_count": 0
},
]
How to update my query to achieve this using IFNULL. Thanks in advance.

Assuming you have set up your model relations correctly, you should be able to do this by chaining:
withCount('status')
Docs: https://laravel.com/docs/8.x/eloquent-relationships#counting-related-models

Related

VSC validation with $schema and usage of additionalProperties = false

i have a dataobject.json and a corresponding example.json. I like to compare both if everything what is in the example is the same notation as in the dataobject.
I added in the exampe the dataobject file as a schema to validate against. This works, but only for the required field, not for the optional properties. - there the validation doesn't find a problem, even if there are some.
To validate these I added the "additionalProperties": false line. This works in general, so I find all the deviations, but I also get a problem that property §schema is not allowed.
How can I solve this?
the dataobject
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"title": "GroupDO",
"required": [
"id",
"name"
],
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "5dd6c80a-3376-4bce-bc47-8t41b3565325",
"description": "Unique id ."
},
"name": {
"type": "string",
"example": "ABD",
"description": "The name."
},
"GroupSort": {
"type": "integer",
"format": "int32",
"example": 1,
"description": "Defines in which order the groups should appear."
},
"GroupTextList": {
"type": "array",
"description": "A descriptoin in multiple languages.",
"items": {
"$ref": "../../common/dataobjects/Description_1000_DO.json"
}
},
"parentGroupId": {
"type": "string",
"format": "uuid",
"example": "8e590f93-1ab6-40e4-a5f4-aa1eeb2b6a80",
"description": "Unique id for the parent group."
}
},
"description": "DO representing a group object. "}
the example
{ "$schema": "../dataobjects/GroupDO.json",
"id": "18694b46-0833-4790-b780-c7897ap08500",
"version": 1,
"lastChange": "2020-05-12T13:57:39.935305",
"sort": 3,
"name": "STR",
"parentGroupId": "b504273e-61fb-48d1-aef8-c289jk779709",
"GroupTexts": [
{
"id": "7598b668-d9b7-4d27-a489-19e45h2bdad0",
"version": 0,
"lastChange": "2020-03-09T14:14:25.491787",
"languageIsoCode": "de_DE",
"description": "Tasche"
},
{
"id": "376e82f8-837d-4bb2-a21f-a9e0ebd59e23",
"version": 0,
"lastChange": "2020-03-09T14:14:25.491787",
"languageIsoCode": "en_GB",
"description": "Bag"
}
]
}
the problem messages:
property $schema is not allowed
Thanks in advance for your help.

How to add additional fields in FHIR using Extensions?

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?

How to get failed step number in Azure pipeline?

There is a step in my Azure pipeline yaml that requires the step number of the first failed step. Is there a way to retrieve this information (preferably in a bash task)?
The idea is to retrieve the logs of the failed step .../_apis/build/builds/777777/logs/3
I'm not good at bash scripting but you need to:
Call Azure DevOps REST API first on timeline endpoint:
https://dev.azure.com/{{organization}}/{{project}}/_apis/build/builds/3477/timeline?api-version=6.0
where 3477 is your build id.
Then go through response and find first record with result=failed:
{
"previousAttempts": [],
"id": "5caf77c8-9b10-50ef-b5c7-ca89c63e1c86",
"parentId": "12f1170f-54f2-53f3-20dd-22fc7dff55f9",
"type": "Task",
"name": "Run a multi-line script",
"startTime": "2020-09-07T12:00:04.5033333Z",
"finishTime": "2020-09-07T12:00:04.7466667Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "failed",
"resultCode": null,
"changeId": 10,
"lastModified": "0001-01-01T00:00:00",
"workerName": "Hosted Agent",
"order": 4,
"details": null,
"errorCount": 1,
"warningCount": 0,
"url": null,
"log": {
"id": 7,
"type": "Container",
"url": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/builds/3477/logs/7"
},
"task": {
"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
"name": "CmdLine",
"version": "2.164.2"
},
"attempt": 1,
"identifier": null,
"issues": [
{
"type": "error",
"category": "General",
"message": "Bash exited with code '1'.",
"data": {
"type": "error",
"logFileLineNumber": "15"
}
}
]
},
At log property of this record you will find url to your log
"log": {
"id": 7,
"type": "Container",
"url": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/builds/3477/logs/7"
},

ElasticSearch : how to rank on skill rating in full text search?

I have quite a simple case but can't find the good way to solve it:
I have People, their Skills are rated. They also have other information attached (eg: city). All of this is in my ElasticSearch index.
Example:
John
Paris
Python: 7/10
Boris
Paris
Python: 3/10
Mike
Frankfurt
Python: 7/10
I would like to perform a text search only to find people.
If I type "Python", the better rated someone is, the higher it should be
If I type "Python Paris", it should get all people in Paris sorted by Python rating
Here is an example of people document in ES index:
{
"_index": "senso",
"_type": "talent",
"_id": "12469",
"_version": 1,
"found": true,
"_source": {
"id": 12469,
"nickname": "Roger",
"first_name": "Moore",
"last_name": "Bond",
"companyName": null,
"email": "example#example.org",
"city": "Marseille",
"region": "Provence-Alpes-Côte d'Azur",
"internalGlobalRating": 5,
"declaredDailyPrice": 650,
"declaredAnnualSalaryTarget": null,
"boughtDailyPrice": null,
"soldDailyPrice": null,
"skillsRatings": [
{
"skillName": "Direction Artistique Web",
"skillId": 1298,
"rating": 9
},
{
"skillName": "UX Design",
"skillId": 1295,
"rating": 9
},
{
"skillName": "Identité Visuelle",
"skillId": 1319,
"rating": 8
},
{
"skillName": "Illustrator",
"skillId": 1425,
"rating": 9
},
{
"skillName": "Photoshop",
"skillId": 1427,
"rating": 9
},
{
"skillName": "InDesign",
"skillId": 1426,
"rating": 9
}
],
"expertises": [
{
"name": "Direction Artistique Web",
"id": 1298
},
{
"name": "UX Design",
"id": 1295
},
{
"name": "Identité Visuelle",
"id": 1319
}
],
"missionTypes": [
{
"name": "Freelance sur place",
"id": 2
},
{
"name": "Freelance en télétravail",
"id": 3
},
{
"name": "Forfait",
"id": 4
}
],
"tools": [
{
"name": "Illustrator",
"id": 1425
},
{
"name": "Photoshop",
"id": 1427
},
{
"name": "InDesign",
"id": 1426
}
],
"themes": [],
"medias": [],
"organizationType": {
"id": 2,
"name": "Studio"
},
"source": {
"id": 2
},
"spokenLanguages": [
{
"id": 2
},
{
"id": 3
}
],
"mainLanguage": {
"id": 1,
"name": "Français"
}
"created": "2011-10-05T20:17:52+02:00",
"updated": "2017-07-03T15:59:11+02:00",
"applicationDate": "2011-10-05T20:17:52+02:00",
"portfolio": {
"id": 95,
"visible": true,
"submissionTime": "2017-01-13T18:20:31+01:00",
"isDisplayed": 1,
"isPublic": 1
}
}
}
I wonder which approach I should choose : tweak at index time or custom queries, or both ?
Any clue on how to tackle this problem would be appreciated.
Thank you.

How to get Order and OrderLineItem for a transaction using Connect V2?

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

Resources