Skip to content

Add support for reverse chain requests using $has #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/Client/FHIRSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ struct FHIRSearchConstruct
FHIRSearchConstructModifierHandler(),
FHIRSearchConstructOperatorHandler(),
FHIRSearchConstructTypeHandler(),
FHIRSearchConstructHasHandler()
]

static func handlerFor(_ key: String) -> FHIRSearchConstructHandler? {
Expand Down Expand Up @@ -514,3 +515,26 @@ struct FHIRSearchConstructTypeHandler: FHIRSearchConstructHandler
}
}

/**
Handles the has operator to allow reverse chain requests.
Expects a tuple of the chained properties and the value to look for: ([String], String)
Example: ["$has": (["Organization", "endpoint", "_id"], "1337")]

See: http://build.fhir.org/search.html#has
*/
struct FHIRSearchConstructHasHandler: FHIRSearchConstructHandler
{
func handles(_ key: String) -> Bool {
return ("$has" == key)
}

func handle(_ param: FHIRSearchParam, value: Any) {
guard let (chain, valueStr) = value as? ([String], String) else {
fhir_warn("$has couldn't be constructed. Got \(value)")
return
}
param.name = "_has:\(chain.joined(separator: ":"))"
param.value = valueStr
}
}