add sort_date as a DB field that can be queried.

make sure that order_by is automatically desc for date fields.
This commit is contained in:
Jason Kulatunga 2023-10-01 19:15:24 -07:00
parent 6d831f6ee7
commit af2344ec00
No known key found for this signature in database
57 changed files with 69 additions and 8 deletions

View File

@ -162,7 +162,7 @@ func (sr *SqliteRepository) sqlQueryResources(ctx context.Context, query models.
//process order by clause
if len(query.Aggregations.OrderBy) > 0 {
orderAsc := true
orderAsc := true //default to ascending, switch to desc if parameter is a date type.
if !strings.HasPrefix(query.Aggregations.OrderBy, "count(*)") {
orderAggregationParam, err := ProcessAggregationParameter(query.Aggregations.OrderBy, searchCodeToTypeLookup)
if err != nil {
@ -174,6 +174,11 @@ func (sr *SqliteRepository) sqlQueryResources(ctx context.Context, query models.
}
fromClauses = append(fromClauses, orderAggregationFromClause)
//if the order by is a date type, we need to order by DESC (most recent first)
if orderAggregationParam.Type == SearchParameterTypeDate {
orderAsc = false
}
orderClause = AggregationParameterToClause(orderAggregationParam)
if orderAsc {
orderClause = fmt.Sprintf("%s ASC", orderClause)
@ -619,7 +624,7 @@ func ProcessAggregationParameter(aggregationFieldWithProperty string, searchPara
}
//primitive types should not have a modifier, we need to throw an error
if aggregationParameter.Type == SearchParameterTypeNumber || aggregationParameter.Type == SearchParameterTypeUri || aggregationParameter.Type == SearchParameterTypeKeyword {
if aggregationParameter.Type == SearchParameterTypeNumber || aggregationParameter.Type == SearchParameterTypeUri || aggregationParameter.Type == SearchParameterTypeKeyword || aggregationParameter.Type == SearchParameterTypeDate {
if len(aggregationParameter.Modifier) > 0 {
return aggregationParameter, fmt.Errorf("primitive aggregation parameter %s cannot have a property (%s)", aggregationParameter.Name, aggregationParameter.Modifier)
}

View File

@ -62,6 +62,7 @@ func (s *FhirAccount) GetSearchParameters() map[string]string {
"owner": "reference",
"period": "date",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -85,6 +85,7 @@ func (s *FhirAdverseEvent) GetSearchParameters() map[string]string {
"resultingcondition": "reference",
"seriousness": "token",
"severity": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -165,6 +165,7 @@ func (s *FhirAllergyIntolerance) GetSearchParameters() map[string]string {
"recorder": "reference",
"route": "token",
"severity": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -101,6 +101,7 @@ func (s *FhirAppointment) GetSearchParameters() map[string]string {
"serviceCategory": "token",
"serviceType": "token",
"slot": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -40,6 +40,7 @@ func (s *FhirBinary) GetSearchParameters() map[string]string {
"language": "token",
"lastUpdated": "date",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -167,6 +167,7 @@ func (s *FhirCarePlan) GetSearchParameters() map[string]string {
"performer": "reference",
"profile": "reference",
"replaces": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -119,6 +119,7 @@ func (s *FhirCareTeam) GetSearchParameters() map[string]string {
"lastUpdated": "date",
"participant": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -101,6 +101,7 @@ func (s *FhirClaim) GetSearchParameters() map[string]string {
"procedureUdi": "reference",
"profile": "reference",
"provider": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -78,6 +78,7 @@ func (s *FhirClaimResponse) GetSearchParameters() map[string]string {
"profile": "reference",
"request": "reference",
"requestor": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -169,6 +169,7 @@ func (s *FhirComposition) GetSearchParameters() map[string]string {
"relatedId": "token",
"relatedRef": "reference",
"section": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -167,6 +167,7 @@ func (s *FhirCondition) GetSearchParameters() map[string]string {
"profile": "reference",
"recordedDate": "date",
"severity": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -147,6 +147,7 @@ func (s *FhirConsent) GetSearchParameters() map[string]string {
"purpose": "token",
"scope": "token",
"securityLabel": "token",
"sort_date": "date",
"sourceReference": "reference",
"source_id": "keyword",
"source_resource_id": "keyword",

View File

@ -74,6 +74,7 @@ func (s *FhirCoverage) GetSearchParameters() map[string]string {
"payor": "reference",
"policyHolder": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -63,6 +63,7 @@ func (s *FhirCoverageEligibilityRequest) GetSearchParameters() map[string]string
"lastUpdated": "date",
"profile": "reference",
"provider": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -71,6 +71,7 @@ func (s *FhirCoverageEligibilityResponse) GetSearchParameters() map[string]strin
"profile": "reference",
"request": "reference",
"requestor": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -76,6 +76,7 @@ func (s *FhirDevice) GetSearchParameters() map[string]string {
"model": "string",
"organization": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -171,6 +171,7 @@ func (s *FhirDeviceRequest) GetSearchParameters() map[string]string {
"priorRequest": "reference",
"profile": "reference",
"requester": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -182,6 +182,7 @@ func (s *FhirDiagnosticReport) GetSearchParameters() map[string]string {
"profile": "reference",
"result": "reference",
"resultsInterpreter": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -114,6 +114,7 @@ func (s *FhirDocumentManifest) GetSearchParameters() map[string]string {
"recipient": "reference",
"relatedId": "token",
"relatedRef": "reference",
"sort_date": "date",
"source": "uri",
"source_id": "keyword",
"source_resource_id": "keyword",

View File

@ -170,6 +170,7 @@ func (s *FhirDocumentReference) GetSearchParameters() map[string]string {
"relation": "token",
"securityLabel": "token",
"setting": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -174,6 +174,7 @@ func (s *FhirEncounter) GetSearchParameters() map[string]string {
"reasonCode": "token",
"reasonReference": "reference",
"serviceProvider": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -63,6 +63,7 @@ func (s *FhirEndpoint) GetSearchParameters() map[string]string {
"organization": "reference",
"payloadType": "token",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -50,6 +50,7 @@ func (s *FhirEnrollmentRequest) GetSearchParameters() map[string]string {
"language": "token",
"lastUpdated": "date",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -51,6 +51,7 @@ func (s *FhirEnrollmentResponse) GetSearchParameters() map[string]string {
"lastUpdated": "date",
"profile": "reference",
"request": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -102,6 +102,7 @@ func (s *FhirExplanationOfBenefit) GetSearchParameters() map[string]string {
"procedureUdi": "reference",
"profile": "reference",
"provider": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -141,6 +141,7 @@ func (s *FhirFamilyMemberHistory) GetSearchParameters() map[string]string {
"profile": "reference",
"relationship": "token",
"sex": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -98,6 +98,7 @@ func (s *FhirGoal) GetSearchParameters() map[string]string {
"lastUpdated": "date",
"lifecycleStatus": "token",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -134,6 +134,7 @@ func (s *FhirImagingStudy) GetSearchParameters() map[string]string {
"reason": "token",
"referrer": "reference",
"series": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -149,6 +149,7 @@ func (s *FhirImmunization) GetSearchParameters() map[string]string {
"reasonCode": "token",
"reasonReference": "reference",
"series": "string",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -91,6 +91,7 @@ func (s *FhirInsurancePlan) GetSearchParameters() map[string]string {
"ownedBy": "reference",
"phonetic": "string",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -91,6 +91,7 @@ func (s *FhirLocation) GetSearchParameters() map[string]string {
"organization": "reference",
"partof": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -81,6 +81,7 @@ func (s *FhirMedia) GetSearchParameters() map[string]string {
"operator": "reference",
"profile": "reference",
"site": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -92,6 +92,7 @@ func (s *FhirMedication) GetSearchParameters() map[string]string {
"lotNumber": "token",
"manufacturer": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -150,6 +150,7 @@ func (s *FhirMedicationAdministration) GetSearchParameters() map[string]string {
"reasonGiven": "token",
"reasonNotGiven": "token",
"request": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -156,6 +156,7 @@ func (s *FhirMedicationDispense) GetSearchParameters() map[string]string {
"profile": "reference",
"receiver": "reference",
"responsibleparty": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -170,6 +170,7 @@ func (s *FhirMedicationRequest) GetSearchParameters() map[string]string {
"priority": "token",
"profile": "reference",
"requester": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -141,6 +141,7 @@ func (s *FhirMedicationStatement) GetSearchParameters() map[string]string {
"medication": "reference",
"partOf": "reference",
"profile": "reference",
"sort_date": "date",
"source": "reference",
"source_id": "keyword",
"source_resource_id": "keyword",

View File

@ -130,6 +130,7 @@ func (s *FhirNutritionOrder) GetSearchParameters() map[string]string {
"oraldiet": "token",
"profile": "reference",
"provider": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -234,6 +234,7 @@ func (s *FhirObservation) GetSearchParameters() map[string]string {
"partOf": "reference",
"performer": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -88,6 +88,7 @@ func (s *FhirOrganization) GetSearchParameters() map[string]string {
"partof": "reference",
"phonetic": "string",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -94,6 +94,7 @@ func (s *FhirOrganizationAffiliation) GetSearchParameters() map[string]string {
"profile": "reference",
"role": "token",
"service": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -223,6 +223,7 @@ func (s *FhirPatient) GetSearchParameters() map[string]string {
"phone": "token",
"phonetic": "string",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -197,6 +197,7 @@ func (s *FhirPerson) GetSearchParameters() map[string]string {
"practitioner": "reference",
"profile": "reference",
"relatedperson": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -197,6 +197,7 @@ func (s *FhirPractitioner) GetSearchParameters() map[string]string {
"phone": "token",
"phonetic": "string",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -114,6 +114,7 @@ func (s *FhirPractitionerRole) GetSearchParameters() map[string]string {
"profile": "reference",
"role": "token",
"service": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -183,6 +183,7 @@ func (s *FhirProcedure) GetSearchParameters() map[string]string {
"profile": "reference",
"reasonCode": "token",
"reasonReference": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -74,6 +74,7 @@ func (s *FhirProvenance) GetSearchParameters() map[string]string {
"profile": "reference",
"recorded": "date",
"signatureType": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -103,6 +103,7 @@ func (s *FhirQuestionnaire) GetSearchParameters() map[string]string {
"name": "string",
"profile": "reference",
"publisher": "string",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -77,6 +77,7 @@ func (s *FhirQuestionnaireResponse) GetSearchParameters() map[string]string {
"partOf": "reference",
"profile": "reference",
"questionnaire": "reference",
"sort_date": "date",
"source": "reference",
"source_id": "keyword",
"source_resource_id": "keyword",

View File

@ -189,6 +189,7 @@ func (s *FhirRelatedPerson) GetSearchParameters() map[string]string {
"phonetic": "string",
"profile": "reference",
"relationship": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -67,6 +67,7 @@ func (s *FhirSchedule) GetSearchParameters() map[string]string {
"profile": "reference",
"serviceCategory": "token",
"serviceType": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -182,6 +182,7 @@ func (s *FhirServiceRequest) GetSearchParameters() map[string]string {
"replaces": "reference",
"requester": "reference",
"requisition": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -69,6 +69,7 @@ func (s *FhirSlot) GetSearchParameters() map[string]string {
"schedule": "reference",
"serviceCategory": "token",
"serviceType": "token",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -78,6 +78,7 @@ func (s *FhirSpecimen) GetSearchParameters() map[string]string {
"lastUpdated": "date",
"parent": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -107,6 +107,7 @@ func (s *FhirVisionPrescription) GetSearchParameters() map[string]string {
"lastUpdated": "date",
"prescriber": "reference",
"profile": "reference",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",

View File

@ -209,6 +209,7 @@ func main() {
d[jen.Lit("source_uri")] = jen.Lit("keyword")
d[jen.Lit("source_resource_id")] = jen.Lit("keyword")
d[jen.Lit("source_resource_type")] = jen.Lit("keyword")
d[jen.Lit("sort_date")] = jen.Lit("date")
}))
g.Return(jen.Id("searchParameters"))