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

Support polymorphic types for nested fields (Task.input.value[x]) #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions fhir-models-gen/cmd/genResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func appendFields(resources ResourceMap, requiredTypes map[string]bool, required
pathParts := Split(element.Path, ".")
if len(pathParts) == level+1 {
// direct childs
name := Title(pathParts[level])
name := title(pathParts[level])

// support contained resources later
if name != "Contained" {
Expand All @@ -347,7 +347,7 @@ func appendFields(resources ResourceMap, requiredTypes map[string]bool, required

typeIdentifier := ""
for _, pathPart := range Split((*element.ContentReference)[1:], ".") {
typeIdentifier = typeIdentifier + Title(pathPart)
typeIdentifier = typeIdentifier + title(pathPart)
}
statement.Id(typeIdentifier).Tag(map[string]string{"json": pathParts[level] + ",omitempty", "bson": pathParts[level] + ",omitempty"})
}
Expand All @@ -362,7 +362,7 @@ func appendFields(resources ResourceMap, requiredTypes map[string]bool, required
default: //polymorphic type
name = Replace(pathParts[level], "[x]", "", -1)
for _, eleType := range element.Type {
name := name + Title(eleType.Code)
name := name + title(eleType.Code)

var err error
i, err = addFieldStatement(resources, requiredTypes, requiredValueSetBindings, file, fields,
Expand Down Expand Up @@ -395,15 +395,16 @@ func addFieldStatement(
elementIndex, level int,
elementType fhir.ElementDefinitionType,
) (idx int, err error) {
fieldName := Title(name)
fieldName := title(name)
element := elementDefinitions[elementIndex]
statement := fields.Id(fieldName)
isPolymorphic := HasSuffix(element.Path, "[x]")

switch elementType.Code {
case "code":
if *element.Max == "*" {
statement.Op("[]")
} else if *element.Min == 0 {
} else if *element.Min == 0 || isPolymorphic {
statement.Op("*")
}

Expand Down Expand Up @@ -441,7 +442,7 @@ func addFieldStatement(
default:
if *element.Max == "*" {
statement.Op("[]")
} else if *element.Min == 0 {
} else if *element.Min == 0 || isPolymorphic {
statement.Op("*")
}

Expand Down Expand Up @@ -472,7 +473,7 @@ func addFieldStatement(
}
}

if *element.Min == 0 {
if *element.Min == 0 || isPolymorphic {
statement.Tag(map[string]string{"json": name + ",omitempty", "bson": name + ",omitempty"})
} else {
statement.Tag(map[string]string{"json": name, "bson": name})
Expand All @@ -491,6 +492,13 @@ func requiredValueSetBinding(elementDefinition fhir.ElementDefinition) *string {
return nil
}

func title(input string) string {
if EqualFold(input, "id") {
return "ID"
}
return Title(input)
}

func typeCodeToTypeIdentifier(typeCode string) string {
switch typeCode {
case "base64Binary":
Expand Down
4 changes: 2 additions & 2 deletions fhir-models/fhir/auditEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ type AuditEventEntityDetail struct {
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
Type string `bson:"type" json:"type"`
ValueString string `bson:"valueString" json:"valueString"`
ValueBase64Binary string `bson:"valueBase64Binary" json:"valueBase64Binary"`
ValueString *string `bson:"valueString,omitempty" json:"valueString,omitempty"`
ValueBase64Binary *string `bson:"valueBase64Binary,omitempty" json:"valueBase64Binary,omitempty"`
}
type OtherAuditEvent AuditEvent

Expand Down
8 changes: 4 additions & 4 deletions fhir-models/fhir/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ type ClaimDiagnosis struct {
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
Sequence int `bson:"sequence" json:"sequence"`
DiagnosisCodeableConcept CodeableConcept `bson:"diagnosisCodeableConcept" json:"diagnosisCodeableConcept"`
DiagnosisReference Reference `bson:"diagnosisReference" json:"diagnosisReference"`
DiagnosisCodeableConcept *CodeableConcept `bson:"diagnosisCodeableConcept,omitempty" json:"diagnosisCodeableConcept,omitempty"`
DiagnosisReference *Reference `bson:"diagnosisReference,omitempty" json:"diagnosisReference,omitempty"`
Type []CodeableConcept `bson:"type,omitempty" json:"type,omitempty"`
OnAdmission *CodeableConcept `bson:"onAdmission,omitempty" json:"onAdmission,omitempty"`
PackageCode *CodeableConcept `bson:"packageCode,omitempty" json:"packageCode,omitempty"`
Expand All @@ -118,8 +118,8 @@ type ClaimProcedure struct {
Sequence int `bson:"sequence" json:"sequence"`
Type []CodeableConcept `bson:"type,omitempty" json:"type,omitempty"`
Date *string `bson:"date,omitempty" json:"date,omitempty"`
ProcedureCodeableConcept CodeableConcept `bson:"procedureCodeableConcept" json:"procedureCodeableConcept"`
ProcedureReference Reference `bson:"procedureReference" json:"procedureReference"`
ProcedureCodeableConcept *CodeableConcept `bson:"procedureCodeableConcept,omitempty" json:"procedureCodeableConcept,omitempty"`
ProcedureReference *Reference `bson:"procedureReference,omitempty" json:"procedureReference,omitempty"`
Udi []Reference `bson:"udi,omitempty" json:"udi,omitempty"`
}
type ClaimInsurance struct {
Expand Down
14 changes: 7 additions & 7 deletions fhir-models/fhir/codeSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ type CodeSystemConceptProperty struct {
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
Code string `bson:"code" json:"code"`
ValueCode string `bson:"valueCode" json:"valueCode"`
ValueCoding Coding `bson:"valueCoding" json:"valueCoding"`
ValueString string `bson:"valueString" json:"valueString"`
ValueInteger int `bson:"valueInteger" json:"valueInteger"`
ValueBoolean bool `bson:"valueBoolean" json:"valueBoolean"`
ValueDateTime string `bson:"valueDateTime" json:"valueDateTime"`
ValueDecimal float64 `bson:"valueDecimal" json:"valueDecimal"`
ValueCode *string `bson:"valueCode,omitempty" json:"valueCode,omitempty"`
ValueCoding *Coding `bson:"valueCoding,omitempty" json:"valueCoding,omitempty"`
ValueString *string `bson:"valueString,omitempty" json:"valueString,omitempty"`
ValueInteger *int `bson:"valueInteger,omitempty" json:"valueInteger,omitempty"`
ValueBoolean *bool `bson:"valueBoolean,omitempty" json:"valueBoolean,omitempty"`
ValueDateTime *string `bson:"valueDateTime,omitempty" json:"valueDateTime,omitempty"`
ValueDecimal *float64 `bson:"valueDecimal,omitempty" json:"valueDecimal,omitempty"`
}
type OtherCodeSystem CodeSystem

Expand Down
6 changes: 3 additions & 3 deletions fhir-models/fhir/communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type CommunicationPayload struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ContentString string `bson:"contentString" json:"contentString"`
ContentAttachment Attachment `bson:"contentAttachment" json:"contentAttachment"`
ContentReference Reference `bson:"contentReference" json:"contentReference"`
ContentString *string `bson:"contentString,omitempty" json:"contentString,omitempty"`
ContentAttachment *Attachment `bson:"contentAttachment,omitempty" json:"contentAttachment,omitempty"`
ContentReference *Reference `bson:"contentReference,omitempty" json:"contentReference,omitempty"`
}
type OtherCommunication Communication

Expand Down
6 changes: 3 additions & 3 deletions fhir-models/fhir/communicationRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type CommunicationRequestPayload struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ContentString string `bson:"contentString" json:"contentString"`
ContentAttachment Attachment `bson:"contentAttachment" json:"contentAttachment"`
ContentReference Reference `bson:"contentReference" json:"contentReference"`
ContentString *string `bson:"contentString,omitempty" json:"contentString,omitempty"`
ContentAttachment *Attachment `bson:"contentAttachment,omitempty" json:"contentAttachment,omitempty"`
ContentReference *Reference `bson:"contentReference,omitempty" json:"contentReference,omitempty"`
}
type OtherCommunicationRequest CommunicationRequest

Expand Down
4 changes: 2 additions & 2 deletions fhir-models/fhir/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type CompositionRelatesTo struct {
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
Code DocumentRelationshipType `bson:"code" json:"code"`
TargetIdentifier Identifier `bson:"targetIdentifier" json:"targetIdentifier"`
TargetReference Reference `bson:"targetReference" json:"targetReference"`
TargetIdentifier *Identifier `bson:"targetIdentifier,omitempty" json:"targetIdentifier,omitempty"`
TargetReference *Reference `bson:"targetReference,omitempty" json:"targetReference,omitempty"`
}
type CompositionEvent struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Expand Down
36 changes: 18 additions & 18 deletions fhir-models/fhir/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ type ContractTermOfferAnswer struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ValueBoolean bool `bson:"valueBoolean" json:"valueBoolean"`
ValueDecimal float64 `bson:"valueDecimal" json:"valueDecimal"`
ValueInteger int `bson:"valueInteger" json:"valueInteger"`
ValueDate string `bson:"valueDate" json:"valueDate"`
ValueDateTime string `bson:"valueDateTime" json:"valueDateTime"`
ValueTime string `bson:"valueTime" json:"valueTime"`
ValueString string `bson:"valueString" json:"valueString"`
ValueUri string `bson:"valueUri" json:"valueUri"`
ValueAttachment Attachment `bson:"valueAttachment" json:"valueAttachment"`
ValueCoding Coding `bson:"valueCoding" json:"valueCoding"`
ValueQuantity Quantity `bson:"valueQuantity" json:"valueQuantity"`
ValueReference Reference `bson:"valueReference" json:"valueReference"`
ValueBoolean *bool `bson:"valueBoolean,omitempty" json:"valueBoolean,omitempty"`
ValueDecimal *float64 `bson:"valueDecimal,omitempty" json:"valueDecimal,omitempty"`
ValueInteger *int `bson:"valueInteger,omitempty" json:"valueInteger,omitempty"`
ValueDate *string `bson:"valueDate,omitempty" json:"valueDate,omitempty"`
ValueDateTime *string `bson:"valueDateTime,omitempty" json:"valueDateTime,omitempty"`
ValueTime *string `bson:"valueTime,omitempty" json:"valueTime,omitempty"`
ValueString *string `bson:"valueString,omitempty" json:"valueString,omitempty"`
ValueUri *string `bson:"valueUri,omitempty" json:"valueUri,omitempty"`
ValueAttachment *Attachment `bson:"valueAttachment,omitempty" json:"valueAttachment,omitempty"`
ValueCoding *Coding `bson:"valueCoding,omitempty" json:"valueCoding,omitempty"`
ValueQuantity *Quantity `bson:"valueQuantity,omitempty" json:"valueQuantity,omitempty"`
ValueReference *Reference `bson:"valueReference,omitempty" json:"valueReference,omitempty"`
}
type ContractTermAsset struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Expand Down Expand Up @@ -239,22 +239,22 @@ type ContractFriendly struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ContentAttachment Attachment `bson:"contentAttachment" json:"contentAttachment"`
ContentReference Reference `bson:"contentReference" json:"contentReference"`
ContentAttachment *Attachment `bson:"contentAttachment,omitempty" json:"contentAttachment,omitempty"`
ContentReference *Reference `bson:"contentReference,omitempty" json:"contentReference,omitempty"`
}
type ContractLegal struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ContentAttachment Attachment `bson:"contentAttachment" json:"contentAttachment"`
ContentReference Reference `bson:"contentReference" json:"contentReference"`
ContentAttachment *Attachment `bson:"contentAttachment,omitempty" json:"contentAttachment,omitempty"`
ContentReference *Reference `bson:"contentReference,omitempty" json:"contentReference,omitempty"`
}
type ContractRule struct {
ID *string `bson:"id,omitempty" json:"id,omitempty"`
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
ContentAttachment Attachment `bson:"contentAttachment" json:"contentAttachment"`
ContentReference Reference `bson:"contentReference" json:"contentReference"`
ContentAttachment *Attachment `bson:"contentAttachment,omitempty" json:"contentAttachment,omitempty"`
ContentReference *Reference `bson:"contentReference,omitempty" json:"contentReference,omitempty"`
}
type OtherContract Contract

Expand Down
4 changes: 2 additions & 2 deletions fhir-models/fhir/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type CoverageCostToBeneficiary struct {
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
Type *CodeableConcept `bson:"type,omitempty" json:"type,omitempty"`
ValueQuantity Quantity `bson:"valueQuantity" json:"valueQuantity"`
ValueMoney Money `bson:"valueMoney" json:"valueMoney"`
ValueQuantity *Quantity `bson:"valueQuantity,omitempty" json:"valueQuantity,omitempty"`
ValueMoney *Money `bson:"valueMoney,omitempty" json:"valueMoney,omitempty"`
Exception []CoverageCostToBeneficiaryException `bson:"exception,omitempty" json:"exception,omitempty"`
}
type CoverageCostToBeneficiaryException struct {
Expand Down
4 changes: 2 additions & 2 deletions fhir-models/fhir/deviceRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type DeviceRequest struct {
Status *RequestStatus `bson:"status,omitempty" json:"status,omitempty"`
Intent RequestIntent `bson:"intent" json:"intent"`
Priority *RequestPriority `bson:"priority,omitempty" json:"priority,omitempty"`
CodeReference Reference `bson:"codeReference" json:"codeReference"`
CodeCodeableConcept CodeableConcept `bson:"codeCodeableConcept" json:"codeCodeableConcept"`
CodeReference *Reference `bson:"codeReference,omitempty" json:"codeReference,omitempty"`
CodeCodeableConcept *CodeableConcept `bson:"codeCodeableConcept,omitempty" json:"codeCodeableConcept,omitempty"`
Parameter []DeviceRequestParameter `bson:"parameter,omitempty" json:"parameter,omitempty"`
Subject Reference `bson:"subject" json:"subject"`
Encounter *Reference `bson:"encounter,omitempty" json:"encounter,omitempty"`
Expand Down
Loading