/// <inheritdoc />
        public List <ParsedPatient> LoadPatients()
        {
            var parser         = new FhirJsonParser();
            var parsedPatients = new List <ParsedPatient>();

            using (var connection = new SQLiteConnection($"Data Source={DatabaseFilename};Version=3;"))
            {
                connection.Open();

                using (var command = new SQLiteCommand("SELECT * FROM Patient", connection))
                {
                    var patientRecords = command.ExecuteReader();
                    while (patientRecords.Read())
                    {
                        var parsedPatient = new ParsedPatient {
                            Seed = new Seed(patientRecords["Seed"] as string), Resources = new List <ParsedResource>()
                        };

                        var patientId = patientRecords["Id"] as string;
                        using (var innerCommand = new SQLiteCommand($"SELECT * FROM Resource WHERE PatientId='{patientId}'", connection))
                        {
                            var resources = innerCommand.ExecuteReader();
                            while (resources.Read())
                            {
                                parsedPatient.Resources.Add(
                                    new ParsedResource
                                {
                                    Resource  = parser.Parse <Resource>(resources["Payload"] as string),
                                    Id        = resources["Id"].ToString(),
                                    PatientId = resources["PatientId"].ToString()
                                });
                            }
                        }

                        parsedPatients.Add(parsedPatient);
                    }
                }
            }

            return(parsedPatients);
        }
Esempio n. 2
0
        public static List <ParsedPatient> ParsePatientFromFiles(string[] fileNames)
        {
            ParsingSyntheaData?.Invoke("SyntheaRunner", EventArgs.Empty);

            var parsedPatients = new List <ParsedPatient>();
            var resourceParser = new FhirJsonParser(
                new ParserSettings {
                AcceptUnknownMembers = true, AllowUnrecognizedEnums = true, PermissiveParsing = true
            });

            foreach (var file in fileNames)
            {
                var json         = File.ReadAllText(file);
                var parsedBundle = resourceParser.Parse <Bundle>(json);
                if (parsedBundle.Entry[0].Resource is Patient)
                {
                    parsedPatients.Add(ParsedPatient.FromBundle(parsedBundle));
                }
            }

            return(parsedPatients);
        }