From 70293f8267d9b6e017f887900dfedcc9b5ec0e04 Mon Sep 17 00:00:00 2001 From: Kathurima Kimathi Date: Thu, 1 Feb 2024 10:09:14 +0300 Subject: [PATCH] setup: diagnostic report model Signed-off-by: Kathurima Kimathi --- .../dto/diagnostic_report_output.go | 5 + pkg/clinical/domain/complex_types.go | 67 ++++++++++ pkg/clinical/domain/complex_types_test.go | 116 ++++++++++++++++++ pkg/clinical/domain/diagnostic_report.go | 40 ++++++ .../usecases/clinical/diagnostic_report.go | 1 + 5 files changed, 229 insertions(+) create mode 100644 pkg/clinical/application/dto/diagnostic_report_output.go create mode 100644 pkg/clinical/domain/diagnostic_report.go create mode 100644 pkg/clinical/usecases/clinical/diagnostic_report.go diff --git a/pkg/clinical/application/dto/diagnostic_report_output.go b/pkg/clinical/application/dto/diagnostic_report_output.go new file mode 100644 index 00000000..09aae275 --- /dev/null +++ b/pkg/clinical/application/dto/diagnostic_report_output.go @@ -0,0 +1,5 @@ +package dto + +type DiagnosticReportOutput struct { + ID string `json:"id,omitempty"` +} diff --git a/pkg/clinical/domain/complex_types.go b/pkg/clinical/domain/complex_types.go index d767cc0b..43d119da 100644 --- a/pkg/clinical/domain/complex_types.go +++ b/pkg/clinical/domain/complex_types.go @@ -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())) +} diff --git a/pkg/clinical/domain/complex_types_test.go b/pkg/clinical/domain/complex_types_test.go index 2f1db7a9..389c25cf 100644 --- a/pkg/clinical/domain/complex_types_test.go +++ b/pkg/clinical/domain/complex_types_test.go @@ -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) + } + }) + } +} diff --git a/pkg/clinical/domain/diagnostic_report.go b/pkg/clinical/domain/diagnostic_report.go new file mode 100644 index 00000000..e7960b0e --- /dev/null +++ b/pkg/clinical/domain/diagnostic_report.go @@ -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"` +} diff --git a/pkg/clinical/usecases/clinical/diagnostic_report.go b/pkg/clinical/usecases/clinical/diagnostic_report.go new file mode 100644 index 00000000..be973de9 --- /dev/null +++ b/pkg/clinical/usecases/clinical/diagnostic_report.go @@ -0,0 +1 @@ +package clinical