Skip to content
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

setup: diagnostic report model #342

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/clinical/application/dto/diagnostic_report_output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dto

type DiagnosticReportOutput struct {
ID string `json:"id,omitempty"`
}
67 changes: 67 additions & 0 deletions pkg/clinical/domain/complex_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3059,3 +3059,70 @@ func (e *MediaStatusEnum) UnmarshalGQL(v interface{}) error {
func (e MediaStatusEnum) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}

// DiagnosticReportStatusEnum is documented here http://hl7.org/fhir/ValueSet/diagnostic-report-status
type DiagnosticReportStatusEnum string

const (
DiagnosticReportStatusRegistered = "registered"
DiagnosticReportStatusPartial = "partial"
DiagnosticReportStatusPreliminary = "preliminary"
DiagnosticReportStatusFinal = "final"
DiagnosticReportStatusAmended = "amended"
DiagnosticReportStatusCorrected = "corrected"
DiagnosticReportStatusAppended = "appended"
DiagnosticReportStatusCancelled = "cancelled"
DiagnosticReportStatusEnteredInError = "entered-in-error"
DiagnosticReportStatusUnknown = "unknown"
)

// AllDiagnosticReportStatusEnum ...
var AllDiagnosticReportStatusEnum = []DiagnosticReportStatusEnum{
DiagnosticReportStatusRegistered,
DiagnosticReportStatusPartial,
DiagnosticReportStatusPreliminary,
DiagnosticReportStatusFinal,
DiagnosticReportStatusAmended,
DiagnosticReportStatusCorrected,
DiagnosticReportStatusAppended,
DiagnosticReportStatusCancelled,
DiagnosticReportStatusEnteredInError,
DiagnosticReportStatusUnknown,
}

// IsValid ...
func (e DiagnosticReportStatusEnum) IsValid() bool {
switch e {
case DiagnosticReportStatusRegistered, DiagnosticReportStatusPartial, DiagnosticReportStatusPreliminary,
DiagnosticReportStatusFinal, DiagnosticReportStatusAmended, DiagnosticReportStatusCorrected, DiagnosticReportStatusAppended,
DiagnosticReportStatusCancelled, DiagnosticReportStatusEnteredInError, DiagnosticReportStatusUnknown:
return true
}

return false
}

// String ...
func (e DiagnosticReportStatusEnum) String() string {
return string(e)
}

// UnmarshalGQL ...
func (e *DiagnosticReportStatusEnum) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}

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

return nil
}

// MarshalGQL writes the composition attester mode to the supplied writer as a quoted string
func (e DiagnosticReportStatusEnum) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
116 changes: 116 additions & 0 deletions pkg/clinical/domain/complex_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4401,3 +4401,119 @@ func TestMediaStatusEnum_MarshalGQL(t *testing.T) {
})
}
}

func TestDiagnosticReportStatusEnum_IsValid(t *testing.T) {
tests := []struct {
name string
c DiagnosticReportStatusEnum
want bool
}{
{
name: "Happy Case - Valid type",
c: DiagnosticReportStatusAmended,
want: true,
},
{
name: "Sad Case - Invalid type",
c: DiagnosticReportStatusEnum("INVALID"),
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.IsValid(); got != tt.want {
t.Errorf("DiagnosticReportStatusEnum.IsValid() = %v, want %v", got, tt.want)
}
})
}
}

func TestDiagnosticReportStatusEnum_String(t *testing.T) {
tests := []struct {
name string
c DiagnosticReportStatusEnum
want string
}{
{
name: "Happy Case",
c: DiagnosticReportStatusAmended,
want: DiagnosticReportStatusAmended,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.String(); got != tt.want {
t.Errorf("DiagnosticReportStatusEnum = %v, want %v", got, tt.want)
}
})
}
}

func TestDiagnosticReportStatusEnum_UnmarshalGQL(t *testing.T) {
validValue := DiagnosticReportStatusUnknown
invalidType := DiagnosticReportStatusEnum("INVALID")
type args struct {
v interface{}
}
tests := []struct {
name string
c *DiagnosticReportStatusEnum
args args
wantErr bool
}{
{
name: "Happy Case - Valid type",
args: args{
v: DiagnosticReportStatusAmended,
},
c: (*DiagnosticReportStatusEnum)(&validValue),
wantErr: false,
},
{
name: "Sad Case - Invalid type",
args: args{
v: "invalid type",
},
c: &invalidType,
wantErr: true,
},
{
name: "Sad Case - Invalid type(float)",
args: args{
v: 45.1,
},
c: (*DiagnosticReportStatusEnum)(&validValue),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.c.UnmarshalGQL(tt.args.v); (err != nil) != tt.wantErr {
t.Errorf("DiagnosticReportStatusEnum.UnmarshalGQL() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestConsentState_MarshalGQL(t *testing.T) {
tests := []struct {
name string
c DiagnosticReportStatusEnum
wantW string
}{
{
name: "valid type enums",
c: DiagnosticReportStatusAmended,
wantW: strconv.Quote("amended"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &bytes.Buffer{}
tt.c.MarshalGQL(w)
if gotW := w.String(); gotW != tt.wantW {
t.Errorf("DiagnosticReportStatusEnum.MarshalGQL() = %v, want %v", gotW, tt.wantW)
}
})
}
}
40 changes: 40 additions & 0 deletions pkg/clinical/domain/diagnostic_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package domain

// DiagnosticReport is documented here http://hl7.org/fhir/StructureDefinition/DiagnosticReport
type DiagnosticReport struct {
ID *string `json:"id,omitempty"`
Meta *FHIRMeta `json:"meta,omitempty"`
ImplicitRules *string `json:"implicitRules,omitempty"`
Language *string `json:"language,omitempty"`
Text *FHIRNarrative `json:"text,omitempty"`
Extension []*Extension `json:"extension,omitempty"`
ModifierExtension []*Extension `json:"modifierExtension,omitempty"`
Identifier []*FHIRIdentifier `json:"identifier,omitempty"`
BasedOn []*FHIRReference `json:"basedOn,omitempty"`
Status DiagnosticReportStatusEnum `json:"status"`
Category []*FHIRCodeableConcept `json:"category,omitempty"`
Code FHIRCodeableConcept `json:"code"`
Subject *FHIRReference `json:"subject,omitempty"`
Encounter *FHIRReference `json:"encounter,omitempty"`
EffectiveDateTime *string `json:"effectiveDateTime,omitempty"`
EffectivePeriod *FHIRPeriod `json:"effectivePeriod,omitempty"`
Issued *string `json:"issued,omitempty"`
Performer []*FHIRReference `json:"performer,omitempty"`
ResultsInterpreter []*FHIRReference `json:"resultsInterpreter,omitempty"`
Specimen []*FHIRReference `json:"specimen,omitempty"`
Result []*FHIRReference `json:"result,omitempty"`
ImagingStudy []*FHIRReference `json:"imagingStudy,omitempty"`
Media []*DiagnosticReportMedia `json:"media,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
ConclusionCode []*FHIRCodeableConcept `json:"conclusionCode,omitempty"`
PresentedForm []*FHIRAttachment `json:"presentedForm,omitempty"`
}

// DiagnosticReportMedia represents the key images associated with this report
type DiagnosticReportMedia struct {
ID *string `json:"id,omitempty"`
Extension []*Extension `json:"extension,omitempty"`
ModifierExtension []*Extension `json:"modifierExtension,omitempty"`
Comment *string `json:"comment,omitempty"`
Link *FHIRReference `json:"link"`
}
1 change: 1 addition & 0 deletions pkg/clinical/usecases/clinical/diagnostic_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package clinical