jq fu

Extracting a Resource from an Array

Extracting a resource from a FHIR Bundle with over 10000 entries, and you know there is a problem at a specific resource, then you can use jq and array processing to extract the resource:

single_patient_bundle-03-09-2020/9b3f6160-285d-4319-8d15-ac07ee3d3a8e.json \
    | jq '.entry[12672].resource'
{
  "id": "99274e87-db14-43fa-9ada-2fcb6c1d68a6",
  "meta": {
    "profile": [
      "http://hl7.org/fhir/StructureDefinition/vitalspanel",
      "http://hl7.org/fhir/StructureDefinition/vitalsigns"
    ]
  },
  "status": "final",
  "resourceType": "Observation"
}```

Extracting two correlated values

Extracting two correlated values, you can use the multiple selectors, such as the following:

cat single_patient_bundle-03-09-2020/9b3f6160-285d-4319-8d15-ac07ee3d3a8e.json \ 
   | jq '.entry[] | "\(.status),\(.resourceType)"' | sort -u 
final,Observation

Checking the Supported Profiles on the IBM FHIR Server

This is a handy curl to check what profiles are loaded on your IBM FHIR Server.

Request

curl -ks -u fhiruser:change-password https://localhost:9443/fhir-server/api/v4/metadata 2>&1 | jq -r '.rest[].resource[] | "\(.type),\(.supportedProfile)"'

Processed Response

PractitionerRole,["http://hl7.org/fhir/us/carin/StructureDefinition/carin-bb-practitionerrole|0.1.0","http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitionerrole|3.1.0","http://hl7.org/fhir/us/davinci-pdex-plan-net/StructureDefinition/plannet-PractitionerRole|0.1.0"]
Procedure,["http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure|3.1.0"]
Provenance,["http://hl7.org/fhir/StructureDefinition/ehrsrle-provenance|4.0.1","http://hl7.org/fhir/StructureDefinition/provenance-relevant-history|4.0.1","http://hl7.org/fhir/us/core/StructureDefinition/us-core-provenance|3.1.0"]
Questionnaire,["http://hl7.org/fhir/StructureDefinition/cqf-questionnaire|4.0.1"]
QuestionnaireResponse,null
RelatedPerson,["http://hl7.org/fhir/us/carin/StructureDefinition/carin-bb-relatedperson|0.1.0"]
RequestGroup,["http://hl7.org/fhir/StructureDefinition/cdshooksrequestgroup|4.0.1"]
ResearchDefinition,null
ResearchElementDefinition,null
ResearchStudy,null
ResearchSubject,null

Extracting Search Parameters with a Type Composite

cat ./fhir-registry/definitions/search-parameters.json | jq -r '.entry[].resource | select(.type == "composite") | .expression' | sort -u

ActivityDefinition.useContext
CapabilityStatement.useContext | CodeSystem.useContext | CompartmentDefinition.useContext | ConceptMap.useContext | GraphDefinition.useContext | ImplementationGuide.useContext | MessageDefinition.useContext | NamingSystem.useContext | OperationDefinition.useContext | SearchParameter.useContext | StructureDefinition.useContext | StructureMap.useContext | TerminologyCapabilities.useContext | ValueSet.useContext
ChargeItemDefinition.useContext
DocumentReference.relatesTo
EffectEvidenceSynthesis.useContext
EventDefinition.useContext
Evidence.useContext
EvidenceVariable.useContext
ExampleScenario.useContext
Group.characteristic
Library.useContext
Measure.useContext
MolecularSequence.referenceSeq
MolecularSequence.variant
Observation
Observation | Observation.component
Observation.component
PlanDefinition.useContext
Questionnaire.useContext
ResearchDefinition.useContext
ResearchElementDefinition.useContext
RiskEvidenceSynthesis.useContext
TestScript.useContext

Extracting Composite Codes from Search Parameters

cat ./fhir-registry/definitions/search-parameters.json | jq -r '.entry[].resource | select(.type == "composite") | .code'

context-type-quantity
context-type-value
context-type-quantity
context-type-value
context-type-quantity
context-type-value
relationship
...
chromosome-variant-coordinate
chromosome-window-coordinate
referenceseqid-variant-coordinate
referenceseqid-window-coordinate
code-value-concept
code-value-date
code-value-quantity
code-value-string
combo-code-value-concept
combo-code-value-quantity
component-code-value-concept
component-code-value-quantity
...
context-type-quantity
context-type-value

Handy Command to get Duplicate Search Parameters

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.