private ThingCollection GetResultGroupFromResponse( string groupName, HealthRecordAccessor accessor, ThingQuery matchingQuery, XPathNavigator groupNavigator) { ThingCollection result = new ThingCollection(groupName, accessor, matchingQuery, _connection); int maxResultsPerRequest = 0; XPathNodeIterator thingNodeIterator = groupNavigator.Select("thing"); XPathNodeIterator unprocessedThingKeyInfoNodeIterator = groupNavigator.Select("unprocessed-thing-key-info"); XPathNavigator filteredNodeNavigator = groupNavigator.SelectSingleNode("filtered"); XPathNavigator orderByCultureNodeNavigator = groupNavigator.SelectSingleNode("order-by-culture"); if (thingNodeIterator != null) { foreach (XPathNavigator thingNode in thingNodeIterator) { ThingBase resultThingBase = DeserializeItem(thingNode); result.AddResult(resultThingBase); maxResultsPerRequest++; } } if (unprocessedThingKeyInfoNodeIterator != null) { foreach (XPathNavigator unprocessedThingKeyInfoNode in unprocessedThingKeyInfoNodeIterator) { XPathNavigator thingIdNavigator = unprocessedThingKeyInfoNode.SelectSingleNode("thing-id"); Guid thingId = Guid.Parse(thingIdNavigator.Value); Guid versionStamp = Guid.Parse(thingIdNavigator.GetAttribute("version-stamp", string.Empty)); ThingKey key = new ThingKey(thingId, versionStamp); result.AddResult(key); } } if (filteredNodeNavigator != null) { result.WasFiltered = filteredNodeNavigator.ValueAsBoolean; } if (orderByCultureNodeNavigator != null) { result.OrderByCulture = orderByCultureNodeNavigator.Value; } if (maxResultsPerRequest > 0) { result.MaxResultsPerRequest = maxResultsPerRequest; } return(result); }
public string TransformItem(string transformName, ThingBase item) { XslCompiledTransform transform = GetTransform(transformName); string thingXml = item.GetItemXml(); StringBuilder result = new StringBuilder(); XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings; XsltArgumentList args = new XsltArgumentList(); args.AddParam("culture", String.Empty, System.Globalization.CultureInfo.CurrentUICulture.Name); args.AddParam("typename", String.Empty, this.ItemTypeDefinition.Name); args.AddParam("typeid", String.Empty, this.ItemTypeDefinition.ToString()); using (XmlWriter writer = XmlWriter.Create(result, settings)) { using (StringReader stringReader = new StringReader(thingXml)) { using (XmlReader reader = XmlReader.Create(stringReader, SDKHelper.XmlReaderSettings)) { XPathDocument thingXmlDoc = new XPathDocument(reader); transform.Transform(thingXmlDoc.CreateNavigator(), args, writer, null); } } writer.Flush(); } return(result.ToString()); }
/// <summary> /// Fills in the data table with data from a list of ThingBase. /// </summary> /// <param name="record"/> /// <param name="items"/> /// <param name="startIndex"/> /// <param name="count"/> public async Task GetDataAsync(HealthRecordAccessor record, IList <ThingBase> items, int startIndex, int count) { ThingDataTableView effectiveView = await this.ApplyEffectiveViewAsync(record.Connection).ConfigureAwait(false); IDictionary <Guid, ThingTypeDefinition> typeDefDict = await ItemTypeManager.GetHealthRecordItemTypeDefinitionAsync(query.TypeIds, record.Connection).ConfigureAwait(false); ThingTypeDefinition sttTypeDef = typeDefDict.Count == 1 ? typeDefDict[query.TypeIds[0]] : null; bool firstRow = true; string transformName = (effectiveView == ThingDataTableView.SingleTypeTable) ? "stt" : "mtt"; for (int i = startIndex; i < items.Count && i < count; ++i) { ThingBase item = items[i]; XPathNavigator itemTransformNav; IDictionary <string, XDocument> transformedXmlData = item.TransformedXmlData; if (transformedXmlData.ContainsKey(transformName)) { itemTransformNav = transformedXmlData[transformName].CreateNavigator().SelectSingleNode( "//data-xml/row"); } else { string transform = (sttTypeDef == null) ? ThingTypeDefinitionHelper.Create(typeDefDict[item.TypeId]).TransformItem(transformName, item) : ThingTypeDefinitionHelper.Create(sttTypeDef).TransformItem(transformName, item); XmlReaderSettings settings = new XmlReaderSettings() { XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; using (StringReader stringReader = new StringReader(transform)) { itemTransformNav = new XPathDocument(XmlReader.Create(stringReader, settings)).CreateNavigator(); } if (!itemTransformNav.MoveToFirstChild()) { continue; } } if (firstRow) { SetupColumns(itemTransformNav.Clone()); firstRow = false; } AddRow(itemTransformNav); } }
public void WhenMedicationTransformedToFhir_ThenMedicationStatementHasTaken() { ThingBase medication = getSampleMedication(); var fhirMedication = medication.ToFhir() as MedicationStatement; Assert.IsNotNull(fhirMedication.Taken); }
internal static Observation DoTransformInternal(Observation observation, ThingBase thing) { observation.SetStatusAsFinal(); observation.CopyIssuedFromAudit(thing.Created); observation.AddCommonData(thing.CommonData); return(observation); }
public override void CopyInto(ThingBase target) { var thingB = target as ThingB; if (thingB == null) { throw new ArgumentException("target is not a ThingB"); } thingB.B = B; base.CopyInto(thingB); }
private ThingBase DeserializeItem(XmlReader thingReader) { string thingString = thingReader.ReadOuterXml(); XmlReader reader = XmlReader.Create(new StringReader(thingString), SDKHelper.XmlReaderSettings); XPathNavigator thingNav = new XPathDocument(reader).CreateNavigator().SelectSingleNode("thing"); ThingBase thingBase = DeserializeItem(thingNav); return(thingBase); }
public void WhenAppSpecificTypesAreRegistered() { HealthServiceResponseData responseData = Samples.SampleUtils.GetResponseData("ApplicationSpecificThing.xml"); _thingTypeRegistrar.RegisterApplicationSpecificHandler( "some-appid", "some-tag", typeof(CustomThingType)); ThingBase thingBase = _thingDeserializer.DeserializeItem(responseData.InfoNavigator.SelectSingleNode("thing")); Assert.IsNotNull(thingBase as CustomThingType); }
/// <summary> /// Do transforms from thing to existing resource /// </summary> /// <param name="resource">A Fhir resource to add transforms to</param> /// <param name="thing">The healthvault thing to get tranforms from</param> public static void DoTransforms(this Resource resource, ThingBase thing) { var transformerType = typeof(ThingBaseToFhir); var method = transformerType.GetRuntimeMethod("DoTransforms", new Type[] { resource.GetType(), thing.GetType() }); if (method != null && method.GetParameters()[0].ParameterType != typeof(Resource)) { method.Invoke(null, new object[] { resource, thing }); } else { resource.DoTransformInternal(thing); } }
internal static T ToFhirInternal <T>(this ThingBase thing) where T : Resource, IExtendable, new() { var resource = new T(); resource.SetIdentity(thing.Key); resource.CopyLastUpdatedFromAudit(thing.LastUpdated); //Extensions resource.AddFlagsAsExtension(thing.Flags); resource.AddStateAsExtension(thing.State); resource.DoTransforms(thing); return(resource); }
/// <summary> /// Transforms a HealthVault thing into a FHIR Resource /// </summary> /// <param name="thing">The HealthVault thing to transform</param> /// <returns>A FHIR resource based on the HealthVault thing</returns> public static Resource ToFhir(this ThingBase thing) { var transformerType = typeof(ThingBaseToFhir); var thingType = thing.GetType(); var method = transformerType.GetRuntimeMethod("ToFhir", new Type[] { thingType }); if (method != null && method.GetParameters()[0].ParameterType != typeof(ThingBase)) { return((Resource)method.Invoke(null, new object[] { thing })); } else { throw new NotImplementedException($"Unable to find tranformer for '{thingType}'"); } }
internal static ThingBase DeserializeItem(XPathNavigator thingNav) { ThingBase result; Guid typeId = GetTypeId(thingNav); ThingTypeHandler handler = null; if (typeId == s_applicationSpecificId) { // Handle application specific health item records by checking for handlers // for the application ID and subtype tag. If the handler doesn't exist // the default handler will be picked up below. AppDataKey appDataKey = GetAppDataKey(thingNav); if (appDataKey != null) { if (s_appSpecificHandlers.ContainsKey(appDataKey.AppId)) { if (s_appSpecificHandlers[appDataKey.AppId].ContainsKey(appDataKey.SubtypeTag)) { handler = s_appSpecificHandlers[appDataKey.AppId][appDataKey.SubtypeTag]; } } } } if (handler == null && TypeHandlers.ContainsKey(typeId)) { handler = TypeHandlers[typeId]; } if (handler != null) { result = (ThingBase)Activator.CreateInstance(handler.ItemTypeClass); } else { result = new ThingBase(typeId); } result.ParseXml(thingNav, thingNav.OuterXml); return(result); }
public ThingBase DeserializeItem(XPathNavigator thingNav) { ThingBase result; Guid typeId = new Guid(thingNav.SelectSingleNode("type-id").Value); Type handler = null; if (typeId == _applicationSpecificTypeId) { // Handle application specific health item records by checking for handlers // for the application ID and subtype tag. If the handler doesn't exist // the default handler will be picked up below. AppDataKey appDataKey = GetAppDataKey(thingNav); if (appDataKey != null) { var appSpecificHandlers = _thingTypeRegistrar.RegisteredAppSpecificHandlers; if (appSpecificHandlers.ContainsKey(appDataKey.AppId)) { if (appSpecificHandlers[appDataKey.AppId].ContainsKey(appDataKey.SubtypeTag)) { handler = appSpecificHandlers[appDataKey.AppId][appDataKey.SubtypeTag]; } } } } if (handler == null && _typeHandlers.ContainsKey(typeId)) { handler = _typeHandlers[typeId]; } if (handler != null) { result = (ThingBase)Activator.CreateInstance(handler); } else { result = new ThingBase(typeId); } result.ParseXml(thingNav, thingNav.OuterXml); return(result); }
static void Main(string[] args) { var thing1 = new Item1(); var thing2 = new Item2(); var thing3 = new Item3(); var thing4 = new Item4(); var things = new ThingBase[] { thing1, thing2, thing3, thing4 }; foreach (var item in things) { item.GetItem(); item.DoThings(); } foreach (var item2 in things) { item2.PrintItem(); } Console.WriteLine("Press Enter To Exit."); Console.ReadLine(); }
public static void DoTransforms(this DocumentReference documentReference, ThingBase thing) { ThingBaseToFhirDocumentReference.DoTransformInternal(documentReference, thing); }
public static void DoTransforms(this Observation observation, ThingBase thing) { ThingBaseToFhirObservation.DoTransformInternal(observation, thing); }
internal BlobStore(ThingBase item, HealthRecordAccessor record) { _item = item; Record = record; }
/// <summary> /// Retracts all facts in the factbase /// </summary> public static void Clear() { FactBase.Clear(); ThingBase.Clear(); }
internal BlobStore( ThingBase item) { _item = item; }
public virtual void CopyInto(ThingBase target) { target.A = A; }
internal void AddResult(ThingBase result) { _abstractResults.Add(result); }
public async Task UpdateThingsAsync <T>(Guid recordId, ICollection <T> things) where T : IThing { Validator.ThrowIfArgumentNull(things, nameof(things), Resources.UpdateItemNull); StringBuilder infoXml = new StringBuilder(128); XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings; bool somethingRequiresUpdate = false; using (XmlWriter infoXmlWriter = XmlWriter.Create(infoXml, settings)) { foreach (IThing thing in things) { Validator.ThrowIfArgumentNull(thing, nameof(things), Resources.UpdateItemsArgumentNull); if (thing.Key == null) { throw new ArgumentException(Resources.UpdateThingWithNoId, nameof(things)); } if ((thing as ThingBase)?.WriteItemXml(infoXmlWriter, false) == true) { somethingRequiresUpdate = true; } } infoXmlWriter.Flush(); } if (somethingRequiresUpdate) { HealthServiceResponseData response = await _connection.ExecuteAsync( HealthVaultMethods.PutThings, 2, infoXml.ToString(), recordId, correlationId : CorrelationId); XPathNodeIterator thingIds = response.InfoNavigator.Select( GetThingIdXPathExpression(response.InfoNavigator)); using (var enumerator = things.GetEnumerator()) { foreach (XPathNavigator thingIdNav in thingIds) { ThingBase thingBase = enumerator.Current as ThingBase; if (thingBase != null) { thingBase.Key = new ThingKey( new Guid(thingIdNav.Value), new Guid(thingIdNav.GetAttribute( "version-stamp", string.Empty))); thingBase.ClearDirtyFlags(); } enumerator.MoveNext(); } } } }
public static void DoTransformInternal(this Resource observation, ThingBase thing) { //NOP }
internal static DocumentReference DoTransformInternal(DocumentReference documentReference, ThingBase thing) { documentReference.SetStatusAsCurrent(); documentReference.SetIndexed(thing.EffectiveDate); documentReference.SetType(); documentReference.AddCommonData(thing.CommonData); return(documentReference); }