Skip to content

Commit

Permalink
adding ability to generate slices of fhir resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Feb 23, 2024
1 parent 6cd68d8 commit 916e4ff
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/pkg/models/database/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ func main() {
})
})

//Similar to NewFhirResourceModelByType, this is a function which returns a slice corresponding FhirResource when provided the FhirResource type string
//uses a switch statement to return the correct type
utilsFile.Comment("Returns a map of all the resource names to their corresponding go struct")
utilsFile.Func().Id("NewFhirResourceModelSliceByType").Params(jen.Id("resourceType").String()).Params(jen.Interface(), jen.Error()).BlockFunc(func(g *jen.Group) {
g.Switch(jen.Id("resourceType")).BlockFunc(func(s *jen.Group) {
for _, resourceName := range AllowedResources {
s.Case(jen.Lit(resourceName)).BlockFunc(func(c *jen.Group) {
c.Return(jen.Index().Id("Fhir"+resourceName).Values(), jen.Nil())
})
}
s.Default().BlockFunc(func(d *jen.Group) {
d.Return(jen.Nil(), jen.Qual("fmt", "Errorf").Call(jen.Lit("Invalid resource type for model: %s"), jen.Id("resourceType")))
})
})
})

//A function which returns the GORM table name for a FHIRResource when provided the FhirResource type string
//uses a switch statement to return the correct type
utilsFile.Comment("Returns the GORM table name for a FHIRResource when provided the FhirResource type string")
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/models/database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type IFhirResourceModel interface {
models.OriginBaser
SetOriginBase(originBase models.OriginBase)
SetResourceRaw(resourceRaw datatypes.JSON)
GetResourceRaw() datatypes.JSON
SetSortTitle(sortTitle *string)
SetSortDate(sortDate *time.Time)
SetSourceUri(sourceUri *string)
Expand Down
118 changes: 118 additions & 0 deletions backend/pkg/models/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,124 @@ func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error)
}
}

// Returns a map of all the resource names to their corresponding go struct
func NewFhirResourceModelSliceByType(resourceType string) (interface{}, error) {
switch resourceType {
case "Account":
return []FhirAccount{}, nil
case "AdverseEvent":
return []FhirAdverseEvent{}, nil
case "AllergyIntolerance":
return []FhirAllergyIntolerance{}, nil
case "Appointment":
return []FhirAppointment{}, nil
case "Binary":
return []FhirBinary{}, nil
case "CarePlan":
return []FhirCarePlan{}, nil
case "CareTeam":
return []FhirCareTeam{}, nil
case "Claim":
return []FhirClaim{}, nil
case "ClaimResponse":
return []FhirClaimResponse{}, nil
case "Composition":
return []FhirComposition{}, nil
case "Condition":
return []FhirCondition{}, nil
case "Consent":
return []FhirConsent{}, nil
case "Coverage":
return []FhirCoverage{}, nil
case "CoverageEligibilityRequest":
return []FhirCoverageEligibilityRequest{}, nil
case "CoverageEligibilityResponse":
return []FhirCoverageEligibilityResponse{}, nil
case "Device":
return []FhirDevice{}, nil
case "DeviceRequest":
return []FhirDeviceRequest{}, nil
case "DiagnosticReport":
return []FhirDiagnosticReport{}, nil
case "DocumentManifest":
return []FhirDocumentManifest{}, nil
case "DocumentReference":
return []FhirDocumentReference{}, nil
case "Encounter":
return []FhirEncounter{}, nil
case "Endpoint":
return []FhirEndpoint{}, nil
case "EnrollmentRequest":
return []FhirEnrollmentRequest{}, nil
case "EnrollmentResponse":
return []FhirEnrollmentResponse{}, nil
case "ExplanationOfBenefit":
return []FhirExplanationOfBenefit{}, nil
case "FamilyMemberHistory":
return []FhirFamilyMemberHistory{}, nil
case "Goal":
return []FhirGoal{}, nil
case "ImagingStudy":
return []FhirImagingStudy{}, nil
case "Immunization":
return []FhirImmunization{}, nil
case "InsurancePlan":
return []FhirInsurancePlan{}, nil
case "Location":
return []FhirLocation{}, nil
case "Media":
return []FhirMedia{}, nil
case "Medication":
return []FhirMedication{}, nil
case "MedicationAdministration":
return []FhirMedicationAdministration{}, nil
case "MedicationDispense":
return []FhirMedicationDispense{}, nil
case "MedicationRequest":
return []FhirMedicationRequest{}, nil
case "MedicationStatement":
return []FhirMedicationStatement{}, nil
case "NutritionOrder":
return []FhirNutritionOrder{}, nil
case "Observation":
return []FhirObservation{}, nil
case "Organization":
return []FhirOrganization{}, nil
case "OrganizationAffiliation":
return []FhirOrganizationAffiliation{}, nil
case "Patient":
return []FhirPatient{}, nil
case "Person":
return []FhirPerson{}, nil
case "Practitioner":
return []FhirPractitioner{}, nil
case "PractitionerRole":
return []FhirPractitionerRole{}, nil
case "Procedure":
return []FhirProcedure{}, nil
case "Provenance":
return []FhirProvenance{}, nil
case "Questionnaire":
return []FhirQuestionnaire{}, nil
case "QuestionnaireResponse":
return []FhirQuestionnaireResponse{}, nil
case "RelatedPerson":
return []FhirRelatedPerson{}, nil
case "Schedule":
return []FhirSchedule{}, nil
case "ServiceRequest":
return []FhirServiceRequest{}, nil
case "Slot":
return []FhirSlot{}, nil
case "Specimen":
return []FhirSpecimen{}, nil
case "VisionPrescription":
return []FhirVisionPrescription{}, nil
default:
return nil, fmt.Errorf("Invalid resource type for model: %s", resourceType)
}
}

// Returns the GORM table name for a FHIRResource when provided the FhirResource type string
func GetTableNameByResourceType(resourceType string) (string, error) {
switch resourceType {
Expand Down

0 comments on commit 916e4ff

Please sign in to comment.