Пример #1
0
        public async Task <GetMedicalfileResult> Handle(GetMedicalfileQuery request, CancellationToken cancellationToken)
        {
            var result = await _medicalfileQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                throw new UnknownMedicalfileException(request.Id, string.Format(Global.UnknownMedicalFile, request.Id));
            }

            return(result.ToResult());
        }
Пример #2
0
        public async Task <SearchPharmaceuticalPrescriptionResult> Handle(GetOpenedPharmaceuticalPrescriptionsQuery query, CancellationToken token)
        {
            SAMLAssertion assertion;
            var           medicalfile = await _medicalFileQueryRepository.Get(query.MedicalfileId, token);

            if (medicalfile == null)
            {
                throw new UnknownPrescriptionException(query.MedicalfileId, string.Format(Global.UnknownMedicalFile, query.MedicalfileId));
            }

            try
            {
                assertion = SAMLAssertion.Deserialize(query.AssertionToken);
            }
            catch
            {
                throw new BadAssertionTokenException(Global.BadAssertionToken);
            }

            var result = await _prescriptionService.GetOpenedPrescriptions(new GetPrescriptionsParameter
            {
                PatientNiss = medicalfile.PatientNiss,
                Page        = new Page
                {
                    PageNumber = 0
                },
                Assertion = assertion
            }, token);

            return(new SearchPharmaceuticalPrescriptionResult
            {
                HasMoreResults = result.HasMoreResults,
                Prescriptions = result.Prescriptions.Select(_ => new SearchPharmaceuticalPrescriptionResult.PharmaceuticalPrescriptionResult
                {
                    RID = _,
                    Status = "opened"
                }).ToList()
            });
        }
Пример #3
0
        public async Task <string> Handle(AddPharmaceuticalPrescriptionCommand command, CancellationToken token)
        {
            SAMLAssertion assertion;
            var           medicalfile = await _medicalfileQueryRepository.Get(command.MedicalfileId, token);

            if (medicalfile == null)
            {
                throw new UnknownPatientException(command.MedicalfileId, string.Format(Global.UnknownMedicalFile, command.MedicalfileId));
            }

            try
            {
                assertion = SAMLAssertion.Deserialize(command.AssertionToken);
            }
            catch
            {
                throw new BadAssertionTokenException(Global.BadAssertionToken);
            }

            var createDateTime = DateTime.UtcNow;

            if (command.CreateDateTime != null)
            {
                createDateTime = command.CreateDateTime.Value;
            }

            var niss       = assertion.AttributeStatement.Attribute.First(_ => _.AttributeNamespace == EHealth.Constants.AttributeStatementNamespaces.Identification).AttributeValue;
            var profession = assertion.AttributeStatement.Attribute.First(_ => _.AttributeNamespace == EHealth.Constants.AttributeStatementNamespaces.Certified).AttributeName;
            var cbe        = _keyStoreManager.GetOrgAuthCertificate().Certificate.ExtractCBE();
            var msgType    = new KmehrMessageBuilder()
                             .AddSender((_) =>
            {
                _.AddHealthCareParty((_) =>
                {
                    _.AddOrganization(cbe, "application", _options.ProductName);
                });
                _.AddHealthCareParty((_) =>
                {
                    _.AddPerson(niss, MAPPING_CLAIM_TO_HCPARTY[profession], string.Empty, string.Empty);
                });
            })
                             .AddRecipient((_) =>
            {
                _.AddHealthCareParty((s) =>
                {
                    s.AddOrganization("RECIPE", "orgpublichealth", "Recip-e");
                });
            })
                             .AddFolder("1", (_) =>
            {
                _.New(medicalfile.PatientNiss, medicalfile.PatientLastname, new string[] { medicalfile.PatientFirstname });
            }, (_) =>
            {
                _.AddTransaction((tr) =>
                {
                    tr.NewPharmaceuticalPrescriptionTransaction("1", createDateTime, true, true, command.ExpirationDateTime)
                    .AddAuthor(niss, MAPPING_CLAIM_TO_HCPARTY[profession], string.Empty, string.Empty)
                    .AddTransactionHeading((h) =>
                    {
                        h.NewPrescriptionHeading("1");
                        foreach (var pharmaPrescription in command.Medications)
                        {
                            h.AddMedicationTransactionItem((ti) =>
                            {
                                ti.SetMedicinalProduct(pharmaPrescription.PackageCode, string.Empty);
                                if (pharmaPrescription.Posology.Type.Code == PosologyTypes.FreeText.Code)
                                {
                                    var freeText = pharmaPrescription.Posology as AddPosologyFreeTextCommand;
                                    ti.SetPosologyFreeText(freeText.Content, DEFAULT_LANGUAGE);
                                }
                                else
                                {
                                    // TODO : MANAGE STRUCTURED POSOLOGY.
                                }

                                if (pharmaPrescription.BeginMoment != null)
                                {
                                    ti.SetBeginMoment(pharmaPrescription.BeginMoment.Value);
                                }

                                if (!string.IsNullOrWhiteSpace(pharmaPrescription.InstructionForPatient))
                                {
                                    ti.SetInstructionForPatient(pharmaPrescription.InstructionForPatient, DEFAULT_LANGUAGE);
                                }

                                if (!string.IsNullOrWhiteSpace(pharmaPrescription.InstructionForReimbursement))
                                {
                                    ti.SetInstructionForReimbursement(pharmaPrescription.InstructionForReimbursement, DEFAULT_LANGUAGE);
                                }
                            });
                        }
                    });
                });
            })
                             .Build(createDateTime);
            var result = await _recipeService.CreatePrescription(Enum.GetName(typeof(PrescriptionTypes), command.PrescriptionType), medicalfile.PatientNiss, command.ExpirationDateTime.Value, msgType, assertion);

            return(result.RID);
        }