adding ability to generate slices of fhir resources.
This commit is contained in:
parent
9466d2bbf3
commit
c3184fa8c0
|
@ -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
|
//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
|
//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")
|
utilsFile.Comment("Returns the GORM table name for a FHIRResource when provided the FhirResource type string")
|
||||||
|
|
|
@ -11,6 +11,7 @@ type IFhirResourceModel interface {
|
||||||
models.OriginBaser
|
models.OriginBaser
|
||||||
SetOriginBase(originBase models.OriginBase)
|
SetOriginBase(originBase models.OriginBase)
|
||||||
SetResourceRaw(resourceRaw datatypes.JSON)
|
SetResourceRaw(resourceRaw datatypes.JSON)
|
||||||
|
GetResourceRaw() datatypes.JSON
|
||||||
SetSortTitle(sortTitle *string)
|
SetSortTitle(sortTitle *string)
|
||||||
SetSortDate(sortDate *time.Time)
|
SetSortDate(sortDate *time.Time)
|
||||||
SetSourceUri(sourceUri *string)
|
SetSourceUri(sourceUri *string)
|
||||||
|
|
|
@ -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
|
// Returns the GORM table name for a FHIRResource when provided the FhirResource type string
|
||||||
func GetTableNameByResourceType(resourceType string) (string, error) {
|
func GetTableNameByResourceType(resourceType string) (string, error) {
|
||||||
switch resourceType {
|
switch resourceType {
|
||||||
|
|
Loading…
Reference in New Issue