public async Task <GetPatientQueryResult> Handle(GetPatientByNissQuery query, CancellationToken token) { var result = await _patientQueryRepository.GetByNiss(query.Niss, token); if (result == null) { throw new UnknownPatientException(query.Niss, string.Format(Global.UnknownPatient, query.Niss)); } return(result.ToResult()); }
public async Task <GetPharmaceuticalPrescriptionResult> Handle(GetPharmaceuticalPrescriptionQuery query, CancellationToken token) { SAMLAssertion assertion = null; try { assertion = SAMLAssertion.Deserialize(query.AssertionToken); } catch { throw new BadAssertionTokenException(Global.BadAssertionToken); } var prescription = await _prescriptionService.GetPrescription(new GetPrescriptionParameter { PrescriptionId = query.PrescriptionId, Assertion = assertion }, token); if (prescription == null) { throw new UnknownPrescriptionException(query.PrescriptionId, string.Format(Global.UnknownPrescription, query.PrescriptionId)); } var patient = await _patientQueryRepository.GetByNiss(prescription.PatientNiss, token); var cnkCodes = prescription.Medications.Select(m => m.PackageCode); var lst = new List <Task <AmpResult> >(); foreach (var cnkCode in cnkCodes) { lst.Add(_ampService.SearchByCnkCode(DeliveryEnvironments.Public.Code, cnkCode, token)); } var ampLst = await Task.WhenAll(lst); return(prescription.ToResult(patient, ampLst.ToList())); }