示例#1
0
 /// <summary>
 ///     Parse Dataset
 /// </summary>
 /// <param name="prop"></param>
 /// <param name="dataset"></param>
 public void Parse(FHIRMapping prop, CSVDataset dataset)
 {
     foreach (var row in dataset.Rows)
     {
         var rowId = GetBaseResourceId(prop.BaseResourceId, row);
         foreach (var mapping in prop.PropertyMapping)
         {
             Parse(rowId, prop.BaseReferenceUrl, mapping, row);
         }
     }
 }
示例#2
0
        private static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("============================");
                Console.WriteLine("FHIR Converter Tool usage");
                Console.WriteLine("FHIRConverter.exe [CSV Flat File] [Mapping json] [Output Json]");
            }

            var mapping = FHIRMapping.FromJson(args[1]);
            var store   = new SimpleFHIRStore();
            var parser  = new FHIRParser(store);
            var dataset = CSVLoader.LoadCSV(args[0], true, ',');

            parser.Parse(mapping, dataset);
            parser.Flush();
            store.SaveJson(args[1]);
        }
示例#3
0
        private FHIRMapping CreateTestMapping()
        {
            var mappings = new List <FHIRPropertyMapping>()
            {
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 0,
                    ColumnName        = "PersonID",
                    ResourceId        = "0000001001",
                    ResourcePath      = "ResearchSubject/Id",
                    ResourceBaseType  = "ResearchSubject",
                    ResourcePathTypes = "ResearchSubject/String",
                },
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 0,
                    ColumnName        = "PersonID",
                    ResourceId        = "0000001001",
                    ResourcePath      = "ResearchSubject/Study/Reference",
                    ResourceBaseType  = "ResearchSubject",
                    ResourcePathTypes = "ResearchSubject/ResourceReference/String",
                    ValueTemplate     = "http://www.silicofcm.com/fhir/researchStudy/study1",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "ResearchSubject/Study/Type",
                            ResourcePathTypes = "ResearchSubject/ResourceReference/String",
                            Value             = "ResearchStudy"
                        }
                    }
                },
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 2,
                    ColumnName        = "Age",
                    ResourceId        = "{RowNumber}002002",
                    ResourcePath      = "Observation/Value/Value",
                    ResourceBaseType  = "Observation",
                    ResourcePathTypes = "Observation/SimpleQuantity/Double",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Code/Text",
                            ResourcePathTypes = "Observation/CodeableConcept/String",
                            Value             = "Age"
                        }
                    }
                },

                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 0,
                    ColumnName        = "PersonID",
                    ResourceId        = "{RowNumber}002002",
                    ResourcePath      = "Observation/Subject/Reference",
                    ResourceBaseType  = "Observation",
                    ResourcePathTypes = "Observation/ResourceReference/String",
                    ValueTemplate     = "http://www.silicofcm.com/fhir/researchSubject/{value}",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Subject/Type",
                            ResourcePathTypes = "Observation/ResourceReference/String",
                            Value             = "ResearchSubject"
                        }
                    }
                },


                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 4,
                    ResourceId        = "{RowNumber}002003",
                    ColumnName        = "BP_Diastolic",
                    ResourceBaseType  = "Observation",
                    ResourcePath      = "Observation/Value/Value",
                    ResourcePathTypes = "Observation/SimpleQuantity/Double",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Code/Text",
                            ResourcePathTypes = "Observation/CodeableConcept/String",
                            Value             = "Diastolic Blood Pressure"
                        }
                    }
                },
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 0,
                    ColumnName        = "PersonID",
                    ResourceId        = "{RowNumber}002003",
                    ResourcePath      = "Observation/Subject/Reference",
                    ResourceBaseType  = "Observation",
                    ResourcePathTypes = "Observation/ResourceReference/String",
                    ValueTemplate     = "http://www.silicofcm.com/fhir/researchSubject/{value}",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Subject/Type",
                            ResourcePathTypes = "Observation/ResourceReference/String",
                            Value             = "ResearchSubject"
                        }
                    }
                },
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 1,
                    ResourceId        = "{RowNumber}002003",
                    ColumnName        = "Encounter_Date",
                    ResourceBaseType  = "Observation",
                    ResourcePath      = "Observation/Issued",
                    ResourcePathTypes = "Observation/DateTimeOffset",
                },

                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 1,
                    ResourceId        = "{RowNumber}002002",
                    ColumnName        = "Encounter_Date",
                    ResourceBaseType  = "Observation",
                    ResourcePath      = "Observation/Issued",
                    ResourcePathTypes = "Observation/DateTimeOffset",
                }
            };

            var mapping = new FHIRMapping();

            mapping.BaseReferenceUrl = "http://www.silicofcm.com/fhir";
            mapping.BaseResourceId   = "001{PersonID}";
            mapping.PropertyMapping  = mappings;
            return(mapping);
        }
示例#4
0
        public static async Task <object> Run([HttpTrigger("post")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"{nameof(PatientAdmissionFunc)} triggered on {DateTime.UtcNow}");

            using (var patientTelemetry =
                       new PatientTelemetry(Environment.GetEnvironmentVariable(CommonConstants.InstumentationKey,
                                                                               EnvironmentVariableTarget.Process),
                                            nameof(PatientAdmissionFunc)))
            {
                try
                {
                    var userIdentity  = req.GetRequestContext().Principal.Identity as ClaimsIdentity;
                    var authorization = new ADAuthorization(userIdentity);

                    patientTelemetry.Caller(authorization.GetCallerName());

                    if (false == await authorization.Authorize(CommonConstants.CareLineManagerRole))
                    {
                        patientTelemetry.Unauthorized();
                        return(req.CreateResponse(HttpStatusCode.Unauthorized, new
                        {
                            result = $"Unauthorized {HttpStatusCode.Unauthorized}"
                        }));
                    }

                    // Get request data
                    dynamic data = await req.Content.ReadAsAsync <object>();

                    if (data == null)
                    {
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new
                        {
                            result = "bad request"
                        }));
                    }

                    // convert the input to the corresponding objects
                    InPatient          inPatient    = data.patient.ToObject <InPatient>();
                    Encounter          encounter    = data.encounter.ToObject <Encounter>();
                    List <Observation> observations = data.observations.ToObject <List <Observation> >();
                    List <Condition>   conditions   = data.conditions.ToObject <List <Condition> >();

                    //get resource from key vault
                    var appResources = await Settings.GetAppResources();

                    new SqlEncryptionHelper();

                    //get patient data from FHIR data
                    var patient = FHIRMapping.PopulatePatientData(inPatient, encounter, observations, conditions);

                    try
                    {
                        var predictLengthOfStayService =
                            new PredictLengthOfStayService(appResources.PredictLengthOfStayServiceEndpoint,
                                                           appResources.PredictLengthOfStayServiceApiKey);

                        patientTelemetry.DependencyStarted();
                        patient.PredictedLengthOfStay = await predictLengthOfStayService.PredictLengthOfStay(patient);

                        patientTelemetry.DependencyCompleted(nameof(PredictLengthOfStayService),
                                                             "PredictLengthOfStay", true);
                    }
                    catch (PredictLengthOfStayServiceException ex)
                    {
                        patientTelemetry.DependencyCompleted(nameof(PredictLengthOfStayService),
                                                             "PredictLengthOfStay", false);
                        patientTelemetry.Error(ex);
                    }

                    var hospital = new Hospital(appResources.PatientDbConnectionString);
                    var id       = await hospital.AdmitPatient(patient);

                    if (id == -1)
                    {
                        return(req.CreateResponse(HttpStatusCode.OK, new
                        {
                            result = "invalid encounter id"
                        }));
                    }

                    var existingPatient = await hospital.GetPatient(id);

                    patientTelemetry.Success();
                    return(req.CreateResponse(HttpStatusCode.OK, new
                    {
                        encounterId = existingPatient.Eid,
                        name = $"{existingPatient.FirstName} {existingPatient.MiddleName} {existingPatient.LastName}",
                        gender = existingPatient.Gender,
                        admittedOn = existingPatient.Vdate
                    }));
                }
                catch (AuthorizationException ex)
                {
                    patientTelemetry.Error(ex);

                    return(req.CreateResponse(HttpStatusCode.ExpectationFailed, new
                    {
                        error = ex.Message
                    }));
                }
                catch (Exception ex)
                {
                    patientTelemetry.Error(ex);

                    return(req.CreateResponse(HttpStatusCode.InternalServerError, new
                    {
                        result = "failed"
                    }));
                }
            }
        }
示例#5
0
        public void CreateParserJson()
        {
            FHIRMapping parser = new FHIRMapping();


            parser.PropertyMapping = new List <FHIRPropertyMapping>()
            {
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 1,
                    ColumnName        = "Age",
                    ResourceId        = "001001",
                    ResourcePath      = "Observation/Value/Value",
                    ResourceBaseType  = "Observation",
                    ResourcePathTypes = "Observation/SimpleQuantity/Decimal",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Code/Text",
                            ResourcePathTypes = "Observation/CodeableConcept/String",
                            Value             = "Age"
                        },
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Issued",
                            ResourcePathTypes = "Observation/DateTimeOffset",
                            Value             = "GETDATE"
                        }
                    }
                },
                new FHIRPropertyMapping()
                {
                    ColumnType        = "string",
                    ColumnIndex       = 2,
                    ResourceId        = "001002",
                    ColumnName        = "BMI",
                    ResourceBaseType  = "Observation",
                    ResourcePath      = "Observation/Value/Value",
                    ResourcePathTypes = "Observation/SimpleQuantity/Decimal",
                    FixedProperties   = new List <FHIRProperty>()
                    {
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Code/Text",
                            ResourcePathTypes = "Observation/CodeableConcept/String",
                            Value             = "BMI"
                        },
                        new FHIRProperty()
                        {
                            ResourcePath      = "Observation/Issued",
                            ResourcePathTypes = "Observation/DateTimeOffset",
                            Value             = "GETDATE"
                        }
                    }
                }
            };

            parser.ToJson("parser.json");
        }