Skip to content

Commit

Permalink
chore: add data when provisioning consent
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Feb 17, 2024
1 parent f39a76a commit b155be3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
45 changes: 45 additions & 0 deletions pkg/clinical/application/dto/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,51 @@ func (c *ConsentProvisionTypeEnum) UnmarshalGQL(v interface{}) error {
return nil
}

// ConsentDataMeaningEnum represents the meaning of consent data
type ConsentDataMeaningEnum string

const (
ConsentDataMeaningInstance = "instance"
ConsentDataMeaningRelated = "related"
ConsentDataMeaningDependents = "dependents"
ConsentDataMeaningAuthoredBy = "authoredby"
)

// IsValid checks if the consent data meaning is valid
func (c ConsentDataMeaningEnum) IsValid() bool {
switch c {
case ConsentDataMeaningInstance, ConsentDataMeaningRelated, ConsentDataMeaningDependents, ConsentDataMeaningAuthoredBy:
return true
}

return false
}

// String converts the consent data meaning to string
func (c ConsentDataMeaningEnum) String() string {
return string(c)
}

// MarshalGQL writes the consent data meaning as a quoted string
func (c ConsentDataMeaningEnum) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(c.String()))
}

// UnmarshalGQL reads a JSON and converts it to a consent data meaning enum
func (c *ConsentDataMeaningEnum) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}

*c = ConsentDataMeaningEnum(str)
if !c.IsValid() {
return fmt.Errorf("%s is not a valid ConsentDataMeaningEnum", str)
}

return nil
}

// QuestionnaireResponseStatusEnum a type enum tha represents a questionnaire response status field of questionnaire response
type QuestionnaireResponseStatusEnum string

Expand Down
12 changes: 11 additions & 1 deletion pkg/clinical/domain/consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ type FHIRConsent struct {
Extension []Extension `json:"extension,omitempty"`
}

// ConsentProvision models a fhir consent provision
// FHIRConsentProvision models a fhir consent provision
type FHIRConsentProvision struct {
ID *string `json:"id,omitempty"`
Type *dto.ConsentProvisionTypeEnum `json:"type,omitempty"`
Data []FHIRConsentProvisionData `json:"data,omitempty"`
}

// FHIRConsentProvisionData models a consent provision data
type FHIRConsentProvisionData struct {
Id *string `json:"id,omitempty"`
Extension []Extension `json:"extension,omitempty"`
ModifierExtension []Extension `json:"modifierExtension,omitempty"`
Meaning dto.ConsentDataMeaningEnum `json:"meaning,omitempty"`
Reference *FHIRReference `json:"reference,omitempty"`
}
12 changes: 12 additions & 0 deletions pkg/clinical/usecases/clinical/consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ func (u *UseCasesClinicalImpl) RecordConsent(ctx context.Context, input dto.Cons
return nil, fmt.Errorf("cannot create a consent in a finished encounter")
}

encounterRef := fmt.Sprintf("Encounter/%s", *encounter.Resource.ID)
encounterReference := &domain.FHIRReference{
ID: encounter.Resource.ID,
Reference: &encounterRef,
}

patientID := encounter.Resource.Subject.ID
patientReference := fmt.Sprintf("Patient/%s", *patientID)
subjectReference := &domain.FHIRReference{
Expand Down Expand Up @@ -49,6 +55,12 @@ func (u *UseCasesClinicalImpl) RecordConsent(ctx context.Context, input dto.Cons
}
consentProvision := &domain.FHIRConsentProvision{
Type: &input.Provision,
Data: []domain.FHIRConsentProvisionData{
{
Meaning: dto.ConsentDataMeaningRelated,
Reference: encounterReference,
},
},
}

tags, err := u.GetTenantMetaTags(ctx)
Expand Down

0 comments on commit b155be3

Please sign in to comment.