Exemple #1
0
        public static Hl7.Fhir.Rest.SearchParams ToSearchParams(this Hl7.Fhir.Model.Identifier identifier)
        {
            var searchParams = new Hl7.Fhir.Rest.SearchParams();

            searchParams.Add(SearchParam.Identifier.ToString(), identifier.ToSearchToken());
            return(searchParams);
        }
Exemple #2
0
        public static string ToSearchToken(this Hl7.Fhir.Model.Identifier identifier)
        {
            var token = string.Empty;

            if (!string.IsNullOrEmpty(identifier.System))
            {
                token += $"{identifier.System}|";
            }

            token += identifier.Value;
            return(token);
        }
Exemple #3
0
        private Hl7.Fhir.Model.Patient GeneratePatient(Model.Request.RegistrarInmunizationRequest request)
        {
            var patientIdentifierDNI = new Hl7.Fhir.Model.Identifier
            {
                Use    = Hl7.Fhir.Model.Identifier.IdentifierUse.Usual,
                System = Common.Constants.DomainName.RenaperDniDomain.Value,
                Value  = request.DNI.ToString()
            };

            var patientIdentifierLocal = new Hl7.Fhir.Model.Identifier
            {
                Use    = Hl7.Fhir.Model.Identifier.IdentifierUse.Usual,
                System = Common.Constants.DomainName.LocalDomain.Value,
                Value  = request.LocalPacienteId
            };

            var patientName = new Hl7.Fhir.Model.HumanName
            {
                Use    = Hl7.Fhir.Model.HumanName.NameUse.Official,
                Text   = $"{request.PrimerNombre} {request.PrimerApellido}",
                Family = $"{request.PrimerApellido}",
                Given  = new string[] { request.PrimerNombre, request.OtrosNombres }
            };

            patientName.FamilyElement.Extension.Add(
                new Hl7.Fhir.Model.Extension
            {
                Url   = "http://hl7.org/fhir/StructureDefinition/humanname-fathers-family",
                Value = new Hl7.Fhir.Model.FhirString($"{request.PrimerApellido}")
            });

            var patient = new Hl7.Fhir.Model.Patient
            {
                Id   = "Patient-01",
                Name = new List <Hl7.Fhir.Model.HumanName> {
                    patientName
                },
                Identifier = new List <Hl7.Fhir.Model.Identifier> {
                    patientIdentifierLocal, patientIdentifierDNI
                },
                BirthDate = request.FechaNacimiento.ToString("yyyy-MM-dd"),
                Gender    = (request.Sexo == Common.Constants.Sexo.Femenido) ? Hl7.Fhir.Model.AdministrativeGender.Female : Hl7.Fhir.Model.AdministrativeGender.Male
            };

            return(patient);
        }
Exemple #4
0
    static void Main(string[] args)
    {
      var MyPatient = new Hl7.Fhir.Model.Patient();

      //Patient's Name
      var PatientName = new Hl7.Fhir.Model.HumanName();
      PatientName.Use = Hl7.Fhir.Model.HumanName.NameUse.Official;
      PatientName.Prefix = new string[] { "Mr" };
      PatientName.Given = new string[] { "Sam" };
      PatientName.Family = "Fhirman";
      MyPatient.Name = new List<Hl7.Fhir.Model.HumanName>();
      MyPatient.Name.Add(PatientName);

      //Patient Identifier 
      var PatientIdentifier = new Hl7.Fhir.Model.Identifier();
      PatientIdentifier.System = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
      PatientIdentifier.Value = "8003608166690503";
      MyPatient.Identifier = new List<Hl7.Fhir.Model.Identifier>();
      MyPatient.Identifier.Add(PatientIdentifier);

      Console.WriteLine("Press any key to serialise Resource to the console as XML.");
      Console.ReadKey();
      Console.WriteLine("");
      try
      {
        //attempt to serialize the resource
        string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(MyPatient);
        XDocument xDoc = XDocument.Parse(xml);
        Console.Write(xDoc.ToString());
        Console.WriteLine("");
        Console.WriteLine("");
      }
      catch (Exception Exec)
      {
        Console.Write("Error message: " + Exec.Message);
      }
      Console.Write("Press any key to end.");
      Console.ReadKey();
    }
        public FederarPacienteResponse FederarPaciente(Model.Request.FederarPacienteRequest request)
        {
            var patientIdentifierDNI = new Hl7.Fhir.Model.Identifier
            {
                Use    = Hl7.Fhir.Model.Identifier.IdentifierUse.Usual,
                System = Common.Constants.DomainName.RenaperDniDomain.Value,
                Value  = request.DNI.ToString()
            };

            var patientIdentifierLocal = new Hl7.Fhir.Model.Identifier
            {
                Use    = Hl7.Fhir.Model.Identifier.IdentifierUse.Usual,
                System = Common.Constants.DomainName.LocalDomain.Value,
                Value  = request.LocalId
            };

            var patientName = new Hl7.Fhir.Model.HumanName
            {
                Use    = Hl7.Fhir.Model.HumanName.NameUse.Official,
                Text   = $"{request.PrimerNombre} {request.PrimerApellido}",
                Family = $"{request.PrimerApellido}",
                Given  = new string[] { request.PrimerNombre, request.OtrosNombres },
            };

            patientName.FamilyElement.Extension.Add(
                new Hl7.Fhir.Model.Extension
            {
                Url   = "http://hl7.org/fhir/StructureDefinition/humanname-fathers-family",
                Value = new Hl7.Fhir.Model.FhirString($"{request.PrimerApellido}")
            });

            var patient = new Hl7.Fhir.Model.Patient
            {
                Id        = null, //INPORTANTE
                IdElement = null, //INPORTANTE
                Name      = new List <Hl7.Fhir.Model.HumanName> {
                    patientName
                },
                Identifier = new List <Hl7.Fhir.Model.Identifier> {
                    patientIdentifierLocal, patientIdentifierDNI
                },
                BirthDate = request.FechaNacimiento.ToString("yyyy-MM-dd"),
                Gender    = (request.Sexo == Common.Constants.Sexo.Femenido) ? Hl7.Fhir.Model.AdministrativeGender.Female : Hl7.Fhir.Model.AdministrativeGender.Male
            };

            var serviceUrl = _integrationServicesConfiguration.GetConfigurationService(IntegrationServicesConfiguration.ConfigurationServicesName.BUS);
            //var patientCreateUrl = serviceUrl.GetEndPoint(IntegrationService.ConfigurationEndPointName.PATIENT_POST_CREATE);

            var client = new FhirClient(serviceUrl.BaseURL)
            {
                PreferredFormat = ResourceFormat.Json
            };

            var activity = new ActivityLog
            {
                ActivityTypeDescriptorId = (int)Entities.Activity.ActivityType.FEDERAR_PACIENTE_EN_BUS
            };

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                if (e.Body != null)
                {
                    var requestAdderss = e.RawRequest.Address.ToString();
                    var requestBody    = Encoding.UTF8.GetString(e.Body, 0, e.Body.Length);

                    //Prettify !!!
                    requestBody = JToken.Parse(requestBody).ToString();

                    activity.RequestIsJson       = true;
                    activity.ActivityRequestUI   = requestAdderss;
                    activity.ActivityRequestBody = requestBody;

                    _logger.LogInformation($"Send Request Address:{requestAdderss}");
                    _logger.LogInformation($"Send Request Body:{requestBody}");
                }
            };

            client.OnAfterResponse += (object sender, AfterResponseEventArgs e) =>
            {
                if (e.Body != null)
                {
                    var responseBody = Encoding.UTF8.GetString(e.Body, 0, e.Body.Length);

                    //Prettify !!!
                    responseBody = JToken.Parse(responseBody).ToString();

                    activity.ResponseIsJson       = true;
                    activity.ActivityResponse     = $"Status: {e.RawResponse.StatusCode}";
                    activity.ActivityResponseBody = responseBody;

                    _logger.LogInformation($"Received response with status: {e.RawResponse.StatusCode}");
                    _logger.LogInformation($"Received response with body: {responseBody}");
                }
            };

            var patientRet = client.Create(patient);

            var identifierBus = patient.Identifier.Where(x => x.System == Msn.InteropDemo.Common.Constants.DomainName.FederadorPatientDomain.Value).FirstOrDefault();

            var resp = new Model.Response.FederarPacienteResponse();

            if (identifierBus != null)
            {
                resp.Id = int.Parse(identifierBus.Value);
            }

            _currentContext.RegisterActivityLog(activity);

            return(resp);
        }
        public Hl7.Fhir.Model.Bundle GetPatientsByMatch(int dni,
                                                        string primerApellido,
                                                        string primerNombre,
                                                        string otrosNombres,
                                                        Common.Constants.Sexo sexo,
                                                        DateTime fechaNacimiento)
        {
            if (dni < 10000)
            {
                throw new Exception($"Nro. de documento no válido:{dni} debe ser mayor a 10.000");
            }

            if (string.IsNullOrWhiteSpace(primerApellido))
            {
                throw new ArgumentException("message", nameof(primerApellido));
            }

            if (string.IsNullOrWhiteSpace(primerNombre))
            {
                throw new ArgumentException("message", nameof(primerNombre));
            }

            var patientIdentifier = new Hl7.Fhir.Model.Identifier();

            patientIdentifier.Use    = Hl7.Fhir.Model.Identifier.IdentifierUse.Usual;
            patientIdentifier.System = Common.Constants.DomainName.RenaperDniDomain.Value;
            patientIdentifier.Value  = dni.ToString();

            var patientName = new Hl7.Fhir.Model.HumanName();

            patientName.Use    = Hl7.Fhir.Model.HumanName.NameUse.Official;
            patientName.Text   = $"{primerNombre} {primerApellido}";
            patientName.Family = $"{primerApellido}";
            patientName.Given  = new string[] { primerNombre, otrosNombres };
            patientName.FamilyElement.Extension.Add(
                new Hl7.Fhir.Model.Extension
            {
                Url   = "http://hl7.org/fhir/StructureDefinition/humanname-fathers-family",
                Value = new Hl7.Fhir.Model.FhirString($"{primerApellido}")
            });

            var paramPatient = new Hl7.Fhir.Model.Patient();

            paramPatient.Name = new List <Hl7.Fhir.Model.HumanName> {
                patientName
            };
            paramPatient.Identifier = new List <Hl7.Fhir.Model.Identifier> {
                patientIdentifier
            };
            paramPatient.BirthDate = fechaNacimiento.ToString("yyyy-MM-dd");
            paramPatient.Gender    = (sexo == Common.Constants.Sexo.Femenido) ? Hl7.Fhir.Model.AdministrativeGender.Female : Hl7.Fhir.Model.AdministrativeGender.Male;

            var parameters = new Hl7.Fhir.Model.Parameters();

            parameters.Id = "mymatch";

            parameters.Add("resource", paramPatient);
            parameters.Add("count", new Hl7.Fhir.Model.Integer(5));

            var serviceUrl = _integrationServicesConfiguration.GetConfigurationService(IntegrationServicesConfiguration.ConfigurationServicesName.BUS);
            var patientUrl = serviceUrl.GetEndPoint(IntegrationService.ConfigurationEndPointName.PATIENT_POST_MATCH);

            var activity = new ActivityLog
            {
                ActivityTypeDescriptorId = (int)Entities.Activity.ActivityType.GET_PACIENTE_EN_BUS_MATCH
            };

            var client = new FhirClient(serviceUrl.BaseURL)
            {
                PreferredFormat = ResourceFormat.Json
            };

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                if (e.Body != null)
                {
                    var requestAdderss = e.RawRequest.Address.ToString();
                    var requestBody    = Encoding.UTF8.GetString(e.Body, 0, e.Body.Length);

                    //Prettify !!!
                    requestBody = JToken.Parse(requestBody).ToString();

                    activity.RequestIsJson       = true;
                    activity.ActivityRequestUI   = requestAdderss;
                    activity.ActivityRequestBody = requestBody;

                    _logger.LogInformation($"Send Request Address:{requestAdderss}");
                    _logger.LogInformation($"Send Request Body:{requestBody}");
                }
            };

            client.OnAfterResponse += (object sender, AfterResponseEventArgs e) =>
            {
                if (e.Body != null)
                {
                    var responseBody = Encoding.UTF8.GetString(e.Body, 0, e.Body.Length);

                    //Prettify !!!
                    responseBody = JToken.Parse(responseBody).ToString();

                    activity.ResponseIsJson       = true;
                    activity.ActivityResponse     = $"Status: {e.RawResponse.StatusCode}";
                    activity.ActivityResponseBody = responseBody;

                    _logger.LogInformation($"Received response with status: {e.RawResponse.StatusCode}");
                    _logger.LogInformation($"Received response with body: {responseBody}");
                }
            };

            var resp = client.Operation(new Uri(patientUrl.URL), parameters, false);

            var ret = (Hl7.Fhir.Model.Bundle)resp;

            _currentContext.RegisterActivityLog(activity);

            return(ret);
        }
Exemple #7
0
        private static void CreatePatient()
        {
            //Create a patient resource instance
            var MyPatient = new Hl7.Fhir.Model.Patient();

            //Patient's Name
            var patientName = new Hl7.Fhir.Model.HumanName();

            patientName.Use    = Hl7.Fhir.Model.HumanName.NameUse.Official;
            patientName.Prefix = new string[] { "Mr" };
            patientName.Given  = new string[] { "Sam" };
            patientName.Family = "Fhirman";
            MyPatient.Name     = new List <Hl7.Fhir.Model.HumanName>();
            MyPatient.Name.Add(patientName);

            //Patient Identifier
            var patientIdentifier = new Hl7.Fhir.Model.Identifier();

            patientIdentifier.System = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
            patientIdentifier.Value  = Guid.NewGuid().ToString();
            MyPatient.Identifier     = new List <Hl7.Fhir.Model.Identifier>();
            MyPatient.Identifier.Add(patientIdentifier);

            var service = new Hl7.Fhir.Rest.FhirClient("http://hapi.fhir.org/baseDstu3");

            service.Timeout = (30 * 1000); // 30 segundos

            //Attempt to send the resource to the server endpoint
            Hl7.Fhir.Model.Patient returnedPatient = service.Create <Hl7.Fhir.Model.Patient>(MyPatient);

            try
            {
                //Attempt to send the resource to the server endpoint
                Hl7.Fhir.Model.Patient ReturnedPatient = service.Create <Hl7.Fhir.Model.Patient>(MyPatient);
                Console.WriteLine(string.Format("Resource is available at: {0}", ReturnedPatient.Id));
                Console.WriteLine();

                Console.WriteLine("This is what we sent up: ");
                Console.WriteLine();
                var serializer = new Hl7.Fhir.Serialization.FhirXmlSerializer();
                var xml        = serializer.SerializeToString(MyPatient);
                Console.WriteLine(xml);


                Console.WriteLine();
                Console.WriteLine("This is what we received back: ");
                Console.WriteLine();
                xml = serializer.SerializeToString(ReturnedPatient);
                Console.WriteLine(xml);
                Console.WriteLine();
            }
            catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec)
            {
                //Process any Fhir Errors returned as OperationOutcome resource
                Console.WriteLine();
                Console.WriteLine("An error message: " + FhirOpExec.Message);
                Console.WriteLine();
                var    serializer = new Hl7.Fhir.Serialization.FhirXmlSerializer();
                string xml        = serializer.SerializeToString(FhirOpExec.Outcome);
                Console.WriteLine(xml);
            }
            catch (Exception GeneralException)
            {
                Console.WriteLine();
                Console.WriteLine("An error message: " + GeneralException.Message);
                Console.WriteLine();
            }

            Console.WriteLine("Press any key to end.");
            Console.ReadKey();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            //The fhir server end point address
            string ServiceRootUrl = "http://pyrohealth.net/test/stu3/fhir";

            //Create a patient resource instance
            var MyPatient = new Hl7.Fhir.Model.Patient();

            //Patient's Name
            var PatientName = new Hl7.Fhir.Model.HumanName();

            PatientName.Use    = Hl7.Fhir.Model.HumanName.NameUse.Official;
            PatientName.Prefix = new string[] { "Mr" };
            PatientName.Given  = new string[] { "Sam" };
            PatientName.Family = "Fhirman";
            MyPatient.Name     = new List <Hl7.Fhir.Model.HumanName>();
            MyPatient.Name.Add(PatientName);

            //Patient Identifier
            var PatientIdentifier = new Hl7.Fhir.Model.Identifier();

            PatientIdentifier.System = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
            PatientIdentifier.Value  = "8003608166690503";
            MyPatient.Identifier     = new List <Hl7.Fhir.Model.Identifier>();
            MyPatient.Identifier.Add(PatientIdentifier);

            //Create a client to send to the server at a given endpoint.
            var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl);

            // increase timeouts since the server might be powered down
            FhirClient.Timeout = (60 * 1000);

            Console.WriteLine("Press any key to send to server: " + ServiceRootUrl);
            Console.ReadKey();
            try
            {
                //Attempt to send the resource to the server endpoint
                Hl7.Fhir.Model.Patient ReturnedPatient = FhirClient.Create <Hl7.Fhir.Model.Patient>(MyPatient);
                Console.WriteLine(string.Format("Resource is available at: {0}", ReturnedPatient.Id));
                Console.WriteLine();
                Console.WriteLine("This is what we sent up: ");
                Console.WriteLine();
                string    xml  = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(MyPatient);
                XDocument xDoc = XDocument.Parse(xml);
                Console.WriteLine(xDoc.ToString());
                Console.WriteLine();
                Console.WriteLine("This is what we received back: ");
                Console.WriteLine();
                xml  = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(ReturnedPatient);
                xDoc = XDocument.Parse(xml);
                Console.WriteLine(xDoc.ToString());
                Console.WriteLine();
            }
            catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec)
            {
                //Process any Fhir Errors returned as OperationOutcome resource
                Console.WriteLine();
                Console.WriteLine("An error message: " + FhirOpExec.Message);
                Console.WriteLine();
                string    xml  = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(FhirOpExec.Outcome);
                XDocument xDoc = XDocument.Parse(xml);
                Console.WriteLine(xDoc.ToString());
            }
            catch (Exception GeneralException)
            {
                Console.WriteLine();
                Console.WriteLine("An error message: " + GeneralException.Message);
                Console.WriteLine();
            }
            Console.WriteLine("Press any key to end.");
            Console.ReadKey();
        }
Exemple #9
0
        public static string ToSearchQueryParameter(this Hl7.Fhir.Model.Identifier identifier)
        {
            EnsureArg.IsNotNull(identifier, nameof(identifier));

            return($"identifier={identifier.ToSearchToken()}");
        }