public void PutCdsObservationData(string streamData) { using (HttpClient client = DynamicsCrmHelper.GetHttpClient()) { byte[] byteArray = Encoding.ASCII.GetBytes(streamData); MemoryStream stream = new MemoryStream(byteArray); // convert stream to string StreamReader reader = new StreamReader(stream); Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine()); // Observation Values // id string id = (string)jObject["id"]; // effectivedate string status = (string)jObject["status"]; // effectivedate string date = (string)jObject["effectiveDateTime"]; // patient string patient = (string)jObject["subject"]["reference"]; // Code string code = (string)jObject["code"]["coding"][0]["display"]; // ValueQuantity string value = (string)jObject["valueQuantity"]["value"]; string unit = (string)jObject["valueQuantity"]["unit"]; string system = (string)jObject["valueQuantity"]["system"]; string valueCode = (string)jObject["valueQuantity"]["code"]; JObject observation = new JObject(); observation.Add("msemr_observationid", id); observation.Add("msemr_description", "Santiago calatrava - Observation"); observation.Add("msemr_valuetypequantityvalue", decimal.Parse(value)); observation.Add("msemr_valuequantityunit", unit); var createrequest1 = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress + "msemr_observations"); createrequest1.Content = new StringContent(observation.ToString()); createrequest1.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); HttpResponseMessage createResponse1 = client.SendAsync(createrequest1, HttpCompletionOption.ResponseHeadersRead).Result; if (createResponse1.IsSuccessStatusCode) { } else { throw new Exception(string.Format("Failed to Post Records", createResponse1.ReasonPhrase)); } } }
public void PutCdsObservationData(string streamData) { using (HttpClient client = DynamicsCrmHelper.GetHttpClient()) { byte[] byteArray = Encoding.ASCII.GetBytes(streamData); MemoryStream stream = new MemoryStream(byteArray); // convert stream to string StreamReader reader = new StreamReader(stream); Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine()); // Observation Values // id string id = (string)jObject["id"]; // effectivedate string status = (string)jObject["status"]; // effectivedate string date = (string)jObject["effectiveDateTime"]; // patient string patient = (string)jObject["subject"]["reference"]; // Code string code = (string)jObject["code"]["coding"][0]["display"]; // ValueQuantity string value = (string)jObject["valueQuantity"]["value"]; string unit = (string)jObject["valueQuantity"]["unit"]; string system = (string)jObject["valueQuantity"]["system"]; string valueCode = (string)jObject["valueQuantity"]["code"]; JObject observation = new JObject(); // observation.Add("msemr_observationid", id); // observation.Add("msemr_effectivestart", date); // observation.Add("msemr_effectiveend", date); // observation.Add("msemr_subjecttypepatient", patient); // observation.Add("msemr_code", code); // string jsonFilePath = @"C:\Users\v-rapaga\source\repos\CdsFhir\Src\Microsoft.Health.DynamicsCrm\ObservationInput.json"; // string json = File.ReadAllText(jsonFilePath); using (StreamReader r = new StreamReader("ObservationInput.json")) { string json = r.ReadToEnd(); var fields = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); observation.Add(fields["observationid"], id); observation.Add(fields["effectivestart"], date); observation.Add(fields["effectiveend"], date); observation.Add(fields["comment"], Description); observation.Add(fields["description"], Description); observation.Add(fields["valuetypequantityvalue"], decimal.Parse(value)); observation.Add(fields["valuequantityunit"], unit); } var createrequest1 = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress + "msemr_observations"); createrequest1.Content = new StringContent(observation.ToString()); createrequest1.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); HttpResponseMessage createResponse1 = client.SendAsync(createrequest1, HttpCompletionOption.ResponseHeadersRead).Result; if (createResponse1.IsSuccessStatusCode) { } else { throw new Exception(string.Format("Failed to Post Records", createResponse1.ReasonPhrase)); } } }