private static List <Patient> ReadPatients() { // Call once! const string filePath = @"c:\Users\Asaniel\Documents\last_base_fixed.csv"; try { var lines = File.ReadAllLines(filePath); if (lines.Length == 0) { return(new List <Patient>()); } var dictionaryKeys = lines.First().Split(';'); var patientDictionaries = lines.Skip(1) .Select(line => line.Split(';') .Select((field, index) => new { key = dictionaryKeys[index], value = field }) .ToDictionary(pair => pair.key, pair => pair.value)); return(patientDictionaries.Select(dict => PatientParser.ReadPatientFromDictionary(dict)).ToList()); } catch (Exception ex) { // do nothing TODO: Fix } return(new List <Patient>()); }
public void ShallReturnPatient() { var xml = XDocument.Load("C-CDA_R2-1_CCD.xml"); var element = xml.Root.CdaElement("recordTarget")?.CdaElement("patientRole"); var result = new PatientParser().FromXml(element); result.Should().NotBeNull(); // Shall have id result.Id.Should().NotBeNullOrEmpty(); // US-Core Shall have identifier result.Identifier.Count.Should().BeGreaterThan(0); result.Identifier.All(i => !string.IsNullOrEmpty(i.System) && !string.IsNullOrEmpty(i.Value)).Should() .BeTrue(); // US-Core Shall have name result.Name.Count.Should().BeGreaterThan(0); result.Name.All(n => !string.IsNullOrEmpty(n.Family) && n.Given.Any()).Should().BeTrue(); // US-Core Shall have gender result.Gender.Should().NotBeNull(); result.Address.Count.Should().BeGreaterThan(0); result.Telecom.Count.Should().BeGreaterThan(0); result.BirthDate.Should().NotBeNullOrEmpty(); result.Extension.Count(e => e.Url == "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race").Should() .Be(1); result.Extension.Count(e => e.Url == "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity") .Should().Be(1); }
/// <summary> /// Get a collection of patient given parameter /// </summary> /// <param name="para"> a string of content to be filtered </param> /// <returns> a collection of patient </returns> public async Task <IEnumerable <IPatient> > GetPatientsAsync(string para = "") { var responseString = await client.GetStringAsync(PatientPage + para); var jObject = JObject.Parse(responseString); var patients = new List <IPatient>(); var array = jObject["entry"].Children <JObject>(); // Parsing the data in each json entry and add them into the patient list foreach (var o in array) { PatientParser patientParser = new PatientParser(); var toParse = (JObject)o["resource"]; // Certain practitioner does not have address so only include those have address var checkProperty = toParse.ContainsKey("address"); if (checkProperty) { patients.Add(patientParser.Parse(toParse)); } } return(patients); }
public void NullElementShallReturnNull() { var result = new PatientParser().FromXml(null); result.Should().BeNull(); }