Skip to content

Commit

Permalink
feat: patch patient height observation
Browse files Browse the repository at this point in the history
- This patches patient's height entries
  • Loading branch information
EspiraMarvin committed Jan 18, 2024
1 parent 50e7dfb commit 3461c94
Show file tree
Hide file tree
Showing 28 changed files with 1,377 additions and 210 deletions.
3 changes: 2 additions & 1 deletion pkg/clinical/application/common/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ func PhysicalPostalAddressesToFHIRAddresses(
func MaritalStatusEnumToCodeableConcept(val domain.MaritalStatus) *domain.FHIRCodeableConcept {
sel := true
disp := domain.MaritalStatusDisplay(val)
codingCode := scalarutils.Code(val.String())
output := &domain.FHIRCodeableConcept{
Coding: []*domain.FHIRCoding{
{
Code: scalarutils.Code(val.String()),
Code: &codingCode,
Display: disp,
UserSelected: &sel,
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/clinical/application/dto/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ type ObservationInput struct {
Value string `json:"value,omitempty" validate:"required"`
}

type PatchObservationInput struct {
Value string `json:"value,omitempty" validate:"required"`
}

func (o ObservationInput) Validate() error {
v := validator.New()
err := v.Struct(o)

return err
}

func (o PatchObservationInput) ValidatePatchObservationInput() error {
v := validator.New()
err := v.Struct(o)

return err
}

type PatientInput struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/domain/complex_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ type FHIRCoding struct {
Version *string `json:"version,omitempty"`

// A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).
Code scalarutils.Code `json:"code,omitempty"`
Code *scalarutils.Code `json:"code,omitempty"`

// A representation of the meaning of the code in the system, following the rules of the system.
Display string `json:"display,omitempty"`
Expand Down
11 changes: 8 additions & 3 deletions pkg/clinical/domain/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type FHIRObservation struct {
Category []*FHIRCodeableConcept `json:"category,omitempty"`

// Describes what was observed. Sometimes this is called the observation "name".
Code FHIRCodeableConcept `json:"code,omitempty"`
Code *FHIRCodeableConcept `json:"code,omitempty"`

// The patient, or group of patients, location, or device this observation is about and into whose record the observation is placed. If the actual focus of the observation is different from the subject (or a sample of, part, or region of the subject), the `focus` element or the `code` itself specifies the actual focus of the observation.
Subject *FHIRReference `json:"subject,omitempty"`
Expand Down Expand Up @@ -256,7 +256,7 @@ type FHIRObservationInput struct {
Category []*FHIRCodeableConceptInput `json:"category,omitempty"`

// Describes what was observed. Sometimes this is called the observation "name".
Code FHIRCodeableConceptInput `json:"code,omitempty"`
Code *FHIRCodeableConceptInput `json:"code,omitempty"`

// The patient, or group of patients, location, or device this observation is about and into whose record the observation is placed. If the actual focus of the observation is different from the subject (or a sample of, part, or region of the subject), the `focus` element or the `code` itself specifies the actual focus of the observation.
Subject *FHIRReferenceInput `json:"subject,omitempty"`
Expand Down Expand Up @@ -352,7 +352,7 @@ type FHIRObservationInput struct {
Component []*FHIRObservationComponentInput `json:"component,omitempty"`

// Meta stores more information about the resource
Meta FHIRMetaInput `json:"meta,omitempty"`
Meta *FHIRMetaInput `json:"meta,omitempty"`

// Extension is an optional element that provides additional information not captured in the basic resource definition
Extension []*FHIRExtension `json:"extension,omitempty"`
Expand Down Expand Up @@ -415,3 +415,8 @@ type PagedFHIRObservations struct {
PreviousCursor string
TotalCount int
}

// FHIRObservationRelayPayload is used to return single instance of Observation
type FHIRObservationRelayPayload struct {
Resource *FHIRObservation `json:"resource,omitempty"`
}
33 changes: 33 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1649,3 +1649,36 @@ func (fh StoreImpl) PatchFHIRComposition(_ context.Context, id string, input dom

return resource, nil
}

// GetFHIRObservation retrieves instances of FHIRObservation by ID
func (fh StoreImpl) GetFHIRObservation(_ context.Context, id string) (*domain.FHIRObservationRelayPayload, error) {
resource := &domain.FHIRObservation{}

err := fh.Dataset.GetFHIRResource(observationResourceType, id, resource)
if err != nil {
return nil, fmt.Errorf("unable to get %s with ID %s, err: %w", observationResourceType, id, err)
}

payload := &domain.FHIRObservationRelayPayload{
Resource: resource,
}

return payload, nil
}

// PatchFHIRObservation is ued to patch an observation resource
func (fh StoreImpl) PatchFHIRObservation(_ context.Context, id string, input domain.FHIRObservationInput) (*domain.FHIRObservation, error) {
payload, err := converterandformatter.StructToMap(input)
if err != nil {
return nil, fmt.Errorf("unable to turn %s input into a map: %w", observationResourceType, err)
}

resource := &domain.FHIRObservation{}

err = fh.Dataset.PatchFHIRResource(observationResourceType, id, payload, resource)
if err != nil {
return nil, fmt.Errorf("unable to patch %s resource: %w", observationResourceType, err)
}

return resource, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestStoreImpl_CreateFHIRObservation(t *testing.T) {
args: args{
ctx: context.Background(),
input: domain.FHIRObservationInput{
Code: domain.FHIRCodeableConceptInput{
Code: &domain.FHIRCodeableConceptInput{
Text: "Obs",
},
},
Expand All @@ -162,7 +162,7 @@ func TestStoreImpl_CreateFHIRObservation(t *testing.T) {
args: args{
ctx: context.Background(),
input: domain.FHIRObservationInput{
Code: domain.FHIRCodeableConceptInput{
Code: &domain.FHIRCodeableConceptInput{
Text: "Obs",
},
},
Expand Down Expand Up @@ -842,6 +842,8 @@ func fakePatient() (*domain.FHIRPatient, error) {
nameUse := domain.HumanNameUseEnumOfficial

creation := scalarutils.DateTime("2020-09-24T18:02:38.661033Z")
typeCode := gofakeit.UUID()
maritalStatusCode := scalarutils.Code(domain.MaritalStatusA.String())

patient := domain.FHIRPatient{
ID: &id,
Expand All @@ -855,7 +857,7 @@ func fakePatient() (*domain.FHIRPatient, error) {
{
System: &system,
Version: &version,
Code: scalarutils.Code(id),
Code: (*scalarutils.Code)(&typeCode),
Display: id,
UserSelected: &userSelected,
},
Expand Down Expand Up @@ -940,7 +942,7 @@ func fakePatient() (*domain.FHIRPatient, error) {
MaritalStatus: &domain.FHIRCodeableConcept{
Coding: []*domain.FHIRCoding{
{
Code: scalarutils.Code(domain.MaritalStatusA.String()),
Code: &maritalStatusCode,
Display: domain.MaritalStatusDisplay(domain.MaritalStatusA),
UserSelected: &userSelected,
},
Expand Down
Loading

0 comments on commit 3461c94

Please sign in to comment.