/// <summary> /// Map a user entity to a practitioner /// </summary> protected override Practitioner MapToFhir(Provider model) { // Is there a provider that matches this user? var provider = model.LoadCollection(o => o.Relationships).FirstOrDefault(o => o.RelationshipTypeKey == EntityRelationshipTypeKeys.AssignedEntity)?.LoadProperty(o => o.TargetEntity) as Provider; model = provider ?? model; var retVal = DataTypeConverter.CreateResource <Practitioner>(model); // Identifiers retVal.Identifier = model.LoadCollection(o => o.Identifiers)?.Select(o => DataTypeConverter.ToFhirIdentifier(o)).ToList(); // ACtive retVal.Active = StatusKeys.ActiveStates.Contains(model.StatusConceptKey.Value); // Names retVal.Name = model.LoadCollection(o => o.Names)?.Select(o => DataTypeConverter.ToFhirHumanName(o)).ToList(); // Telecoms retVal.Telecom = model.LoadCollection(o => o.Telecoms)?.Select(o => DataTypeConverter.ToFhirTelecom(o)).ToList(); // Address retVal.Address = model.LoadCollection(p => p.Addresses)?.Select(o => DataTypeConverter.ToFhirAddress(o)).ToList(); // Birthdate retVal.BirthDateElement = DataTypeConverter.ToFhirDate(provider?.DateOfBirth ?? model.DateOfBirth); var photo = (provider?.LoadCollection <EntityExtension>(nameof(Entity.Extensions)) ?? model.LoadCollection <EntityExtension>(nameof(Entity.Extensions)))?.FirstOrDefault(o => o.ExtensionTypeKey == ExtensionTypeKeys.JpegPhotoExtension); if (photo != null) { retVal.Photo = new List <Attachment>() { new Attachment() { ContentType = "image/jpg", Data = photo.ExtensionValueXml } } } ; // Load the koala-fication retVal.Qualification = new List <Practitioner.QualificationComponent>() { new Practitioner.QualificationComponent() { Code = DataTypeConverter.ToFhirCodeableConcept(provider.ProviderSpecialtyKey) } }; // Language of communication retVal.Communication = model.LoadCollection(o => o.LanguageCommunication)?.Select(o => new CodeableConcept("http://tools.ietf.org/html/bcp47", o.LanguageCode)).ToList(); return(retVal); }