public string GetImmunizationsRequest(ImmunizationsPatientIdentification patient)
        {
            var name    = patient.Names.First();
            var address = patient.Addresses.First();

            //DPI WiRId in DEV is 40442
            var environment = ConfigurationManager.AppSettings["Environment"];
            var wirOrgId    = environment?.StartsWith("Prod") == true ? patient.WirSchoolId : "40442";

            var headerMessage = $"MSH|^~\\&|WIDPI|{wirOrgId}|WIR||20200407123605-0600||QBP^Q11^QBP_Q11|20200407-A1|P|2.5.1|||ER|AL|||||Z34^CDCPHINVS|\r\n";
            var queryMessage  = $"QPD|Z34^Request PharmacyTreatmentAdministration History^CDCPHINVS|DPI{patient.UniqueId}||{name.LastSurname}^{name.FirstName}^{name.MiddleName}^^^^L||{patient.Birthdate}|{patient.Gender}|{address.Street}^^{address.City}^{address.State}^{address.Zipcode}^USA^M||\r\n";
            var requestCount  = "RCP|I|5^RD&records&HL70126";

            return($"{headerMessage}{queryMessage}{requestCount}");
        }
예제 #2
0
        public ImmunizationsPatientIdentification GetPatientIdentification(string uniqueId, int[] localEducationOrganizationIds)
        {
            var leaIds  = string.Join(",", localEducationOrganizationIds);
            var patient = new ImmunizationsPatientIdentification();
            var name    = new ImmunizationsPatientName {
                Primary = true
            };
            var address = new ImmunizationsPatientAddress {
                Primary = true
            };
            var sql = $@"
;WITH SeoaAddress AS (
	SELECT [StudentUsi], [EducationOrganizationId],[StreetNumberName], [City], [PostalCode], [StateAbbreviationDescriptorId],
    ROW_NUMBER() OVER (PARTITION BY [StudentUsi], [EducationOrganizationId] ORDER BY [AddressTypeDescriptorId]) AS rn
	FROM [edfi].[StudentEducationOrganizationAssociationAddress] seoaa
	WHERE [AddressTypeDescriptorId] IN (12720, 12721) 
),
StudentSchool AS (
	SELECT ssa.[SchoolId]
		,ssa.[StudentUSI]
		,ssa.[Id]
		,ssa.[LastModifiedDate]
		,ic.[IdentificationCode]
	FROM [edfi].[StudentSchoolAssociation] ssa
    JOIN [edfi].[EducationOrganizationIdentificationCode] ic 
		ON ssa.SchoolId = ic.[EducationOrganizationId]
		AND ic.[EducationOrganizationIdentificationSystemDescriptorId] = 450
)
SELECT   s.[StudentUniqueId]
		,s.[StudentUsi]
        ,seoa.[EducationOrganizationId]
		,s.[Id] StudentId
		,seoa.[Id] StudentEducationOrganizationAssociationId
		,s.[FirstName]
		,s.[MiddleName]
		,s.[LastSurname]
		,s.[BirthDate]
		,isnull(bsd.[CodeValue], 'U') Sex
        ,CASE WHEN ssa.StudentUSI IS NULL THEN CAST(0 AS BIT) ELSE CAST(1 AS BIT) END SsaExists
		,CASE WHEN seoa.StudentUSI IS NULL THEN CAST(0 AS BIT) ELSE CAST(1 AS BIT) END SeoaExists
		,seoaa.[StreetNumberName]
		,seoaa.[City]
		,sad.[CodeValue] [State]
		,seoaa.[PostalCode]
        ,ssa.[IdentificationCode] [WirSchoolId]
  FROM [edfi].[Student] s
  LEFT JOIN StudentSchool ssa
    ON ssa.StudentUSI = s.StudentUSI
    AND ssa.Id  = (SELECT TOP 1 Id
		FROM StudentSchool ssa2
		JOIN [edfi].[School] sc
			ON sc.SchoolId = ssa2.SchoolId
			AND (sc.LocalEducationAgencyId in ({leaIds}) OR sc.SchoolId in ({leaIds}))
		WHERE s.StudentUSI = ssa2.StudentUSI
		ORDER BY ssa2.LastModifiedDate)
  LEFT JOIN [edfi].[StudentEducationOrganizationAssociation] seoa
	ON seoa.Id = 
	(SELECT TOP 1 Id
		FROM [edfi].[StudentEducationOrganizationAssociation] seoa2
        JOIN [edfi].[School] sc2
			ON sc2.SchoolId = seoa2.EducationOrganizationId
			AND (sc2.LocalEducationAgencyId in ({leaIds}) OR sc2.SchoolId in ({leaIds}))
		WHERE s.StudentUSI = seoa2.StudentUSI
		ORDER BY seoa2.LastModifiedDate)
  LEFT JOIN [edfi].[Descriptor] bsd
	ON bsd.DescriptorId = seoa.SexDescriptorId
  LEFT JOIN SeoaAddress seoaa
	ON seoaa.StudentUSI = seoa.StudentUSI
	AND seoaa.EducationOrganizationId = seoa.EducationOrganizationId
    AND seoaa.rn = 1
  LEFT JOIN [edfi].[Descriptor] sad
	ON sad.DescriptorId = seoaa.StateAbbreviationDescriptorId
WHERE [StudentUniqueId] = '{uniqueId}'";

            using (var conn = new SqlConnection(_odsDatabaseConnectionStringProvider.GetConnectionString()))
            {
                conn.Open();

                using (var cmd = new SqlCommand(sql, conn))
                {
                    using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        if (reader.Read())
                        {
                            patient.StudentExists = true;

                            patient.UniqueId = reader.GetString("StudentUniqueId");
                            patient.EducationOrganizationId = reader.GetInt32("EducationOrganizationId");
                            patient.StudentId = reader.GetGuid("StudentId");
                            patient.StudentEducationOrganizationAssociationId = reader.GetGuid("StudentEducationOrganizationAssociationId");

                            name.FirstName      = reader.GetString("FirstName");
                            name.MiddleName     = reader.GetString("MiddleName");
                            name.LastSurname    = reader.GetString("LastSurname");
                            patient.Birthdate   = reader.GetDate("BirthDate")?.ToString("yyyyMMdd");
                            patient.SsaExists   = reader.GetBoolean("SsaExists");
                            patient.SeoaExists  = reader.GetBoolean("SeoaExists");
                            patient.WirSchoolId = reader.GetString("WirSchoolId");

                            patient.Gender  = reader.GetString("Sex");
                            address.City    = reader.GetString("City");
                            address.State   = reader.GetString("State");
                            address.Street  = reader.GetString("StreetNumberName");
                            address.Zipcode = reader.GetString("PostalCode");
                        }
                        patient.Names.Add(name);
                        patient.Addresses.Add(address);
                    }
                }
            }
            return(patient);
        }
예제 #3
0
        public ImmunizationsStudentResponse GetImmunizationsResponse(string message, ImmunizationsPatientIdentification patient)
        {
            var result   = new ImmunizationsStudentResponse();
            var segments = GetSegments(message);

            result.Data = new ImmunizationsStudentHistory
            {
                StudentReference = patient.StudentExists == false ? null : new StudentReference
                {
                    StudentUniqueId = patient.UniqueId,
                    ResourceId      = patient.StudentId
                },
                StudentEducationOrganizationAssociationReference = patient.SeoaExists == false ? null : new StudentEducationOrganizationAssociationReference
                {
                    StudentUniqueId         = patient.UniqueId,
                    EducationOrganizationId = patient.EducationOrganizationId,
                    ResourceId = patient.StudentEducationOrganizationAssociationId
                }
            };

            foreach (var segment in segments)
            {
                var fields      = GetFields(segment);
                var messageType = fields[0];

                switch (messageType)
                {
                case MessageType.MessageHeader:
                    var profile = fields[MshMessageProfileIdentifier];
                    switch (profile)
                    {
                    case MessageProfile.CompleteImmunizationHistory:
                        result.StatusCode = ImmunizationsStatusCode.Success;
                        break;

                    case MessageProfile.ListofCanidates:
                        result.StatusCode = ImmunizationsStatusCode.MultipleMatches;
                        break;

                    case MessageProfile.NoPersonRecords:
                        result.StatusCode = ImmunizationsStatusCode.NotFound;
                        break;
                    }
                    break;

                case MessageType.MessageAcknowledgement:
                    var acknowledgmentCode = fields[MsaAcknowledgmentCode];
                    if (acknowledgmentCode == AcknowledgmentCode.Reject)
                    {
                        result.StatusCode = ImmunizationsStatusCode.Reject;
                    }
                    break;

                case MessageType.PatientIdentification:
                    var patientIdentification = GetParts(fields[PidOrdinalInternalId]);
                    result.Data.PatientIdentifier.Id = patientIdentification.Count > 0 ? patientIdentification[0] : null;
                    result.Data.PatientIdentifier.AssigningAuthority = patientIdentification.Count > 3 ? patientIdentification[3] : null;
                    result.Data.PatientIdentifier.IdentifierTypeCode = patientIdentification.Count > 4 ? patientIdentification[4] : null;

                    var name = GetParts(fields[PidOrdinalPatientName]);
                    result.Data.PatientIdentifier.Name = GetName(name);

                    var mothersMaidenName = GetParts(fields[PidOrdinalMothersMaidenName]);
                    result.Data.PatientIdentifier.MothersMaidenName = GetMaidenName(mothersMaidenName);

                    result.Data.PatientIdentifier.BirthDate = fields.Count > PidOrdinalBirthDate?ToEdFiDate(fields[PidOrdinalBirthDate]) : null;

                    result.Data.PatientIdentifier.Sex  = fields.Count > PidOrdinalSex ? fields[PidOrdinalSex] : null;
                    result.Data.PatientIdentifier.Race = fields.Count > PidOrdinalRace ? fields[PidOrdinalRace] : null;

                    var address = fields[PidOrdinalAddress];
                    result.Data.PatientIdentifier.Address = GetAddress(GetParts(address));

                    //result.Data.PatientIdentifier.EthnicGroup = GetCodedElement(GetParts(fields[PidOrdinalEthnicGroup]));
                    result.Data.PatientIdentifier.MultipleBirthIndicator = ToBool(fields[PidOrdinalMultipleBirthIndicator]);
                    result.Data.PatientIdentifier.BirthOrder             = fields[PidOrdinalBirthOrder];
                    //result.Data.PatientIdentifier.Citizenship = GetCodedElement(GetParts(fields[PidOrdinalCitizenship]));

                    var telephone = fields[PidOrdinalPhoneNumber];
                    result.Data.PatientIdentifier.ExtendedTelephoneNumber = GetTelephoneNumber(GetParts(telephone));


                    break;

                case MessageType.PharmacyTreatmentAdministration:
                    var pharmacyTreatmentAdministration = GetPharmacyTreatmentAdministration(fields);
                    if (pharmacyTreatmentAdministration.CompletionStatus != CompletionStatus.Refusal)
                    {
                        result.Data.PharmacyTreatmentAdministrations.Add(pharmacyTreatmentAdministration);
                    }
                    break;

                case MessageType.Error:
                    result.Errors.Add(new ImmunizationsError
                    {
                        Id           = "100106",
                        Source       = "WiR",
                        Error        = segment,
                        ErrorMessage = fields.Count > 8 ? fields[8] : null
                    });
                    break;
                }
            }

            if (result.StatusCode != ImmunizationsStatusCode.Success)
            {
                result.Data.PatientIdentifier = null;
                result.Data.PharmacyTreatmentAdministrations = null;
            }

            result.Data.PharmacyTreatmentAdministrations = result.Data.PharmacyTreatmentAdministrations?.OrderByDescending(p => p.AdministeredDate).ToList();

            return(result);
        }