Skip to content

Commit

Permalink
feat: patching a FHIR resource instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedy omondi committed Nov 29, 2024
1 parent 61a9fc6 commit 36c96bd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
57 changes: 57 additions & 0 deletions models/operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package models

import "encoding/json"

type Parameters struct {
ID *string `json:"id,omitempty"`
Meta *FHIRMeta `json:"meta,omitempty"`
ImplicitRules *string `json:"implicitRules,omitempty"`
Language *string `json:"language,omitempty"`
Parameter []ParametersParameter `json:"parameter,omitempty"`
}
type ParametersParameter struct {
ID *string `json:"id,omitempty"`
Extension []Extension `json:"extension,omitempty"`
ModifierExtension []Extension `json:"modifierExtension,omitempty"`
Name string `json:"name"`
ValueBase64Binary *string `json:"valueBase64Binary,omitempty"`
ValueBoolean *bool `json:"valueBoolean,omitempty"`
ValueCanonical *string `json:"valueCanonical,omitempty"`
ValueCode *string `json:"valueCode,omitempty"`
ValueDate *string `json:"valueDate,omitempty"`
ValueDateTime *string `json:"valueDateTime,omitempty"`
ValueDecimal *json.Number `json:"valueDecimal,omitempty"`
ValueID *string `json:"valueId,omitempty"`
ValueInstant *string `json:"valueInstant,omitempty"`
ValueInteger *int `json:"valueInteger,omitempty"`
ValueMarkdown *string `json:"valueMarkdown,omitempty"`
ValueOid *string `json:"valueOid,omitempty"`
ValuePositiveInt *int `json:"valuePositiveInt,omitempty"`
ValueString *string `json:"valueString,omitempty"`
ValueTime *string `json:"valueTime,omitempty"`
ValueUnsignedInt *int `json:"valueUnsignedInt,omitempty"`
ValueUrI *string `json:"valueUrI,omitempty"`
ValueUrL *string `json:"valueUrL,omitempty"`
ValueUUID *string `json:"valueUUID,omitempty"`
ValueAddress *FHIRAddress `json:"valueAddress,omitempty"`
ValueAge *FHIRAge `json:"valueAge,omitempty"`
ValueAnnotation *FHIRAnnotation `json:"valueAnnotation,omitempty"`
ValueAttachment *FHIRAttachment `json:"valueAttachment,omitempty"`
ValueCodeableConcept *FHIRCodeableConcept `json:"valueCodeableConcept,omitempty"`
ValueCoding *FHIRCoding `json:"valueCoding,omitempty"`
ValueContactPoint *FHIRContactPoint `json:"valueContactPoint,omitempty"`
ValueDuration *FHIRDuration `json:"valueDuration,omitempty"`
ValueHumanName *FHIRHumanName `json:"valueHumanName,omitempty"`
ValueIdentifier *FHIRIdentifier `json:"valueIdentifier,omitempty"`
ValuePeriod *FHIRPeriod `json:"valuePeriod,omitempty"`
ValueQuantity *FHIRQuantity `json:"valueQuantity,omitempty"`
ValueRange *FHIRRange `json:"valueRange,omitempty"`
ValueRatio *FHIRRatio `json:"valueRatio,omitempty"`
ValueReference *FHIRReference `json:"valueReference,omitempty"`
ValueSampledData *FHIRSampledData `json:"valueSampledData,omitempty"`
ValueTiming *FHIRTiming `json:"valueTiming,omitempty"`
ValueExpression *FHIRExpression `json:"valueExpression,omitempty"`
ValueMeta *FHIRMeta `jsoson:"valueMeta,omitempty"`
Resource json.RawMessage `jsoon:"resource,omitempty"`
Part []ParametersParameter `json:"part,omitempty"`
}
12 changes: 12 additions & 0 deletions operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ func (c *Client) GetEncounterEverything(ctx context.Context, encounterID string,

return &bundle, nil
}

// PatchFHIRResource updates an instance of a fhir resource.
func (c *Client) PatchFHIRResource(ctx context.Context, resourceType string, resourceID string, payload []*models.Parameters, resource interface{}) error {
updatePath := fmt.Sprintf("%v/%v", resourceType, resourceID)

err := c.makeRequest(ctx, http.MethodPatch, updatePath, nil, payload, resource)
if err != nil {
return fmt.Errorf("unable to patch resource: %w", err)
}

return nil
}

0 comments on commit 36c96bd

Please sign in to comment.