public void Go() { SanityCheckOutput(); EMUData emu = new EMUData(prescriptionsFile, itemsFile); emu.Load(); foreach (string pid in emu.GetPrescriptionIDs()) { Bundle b = MakeBundle(emu.GetPrescriptionData(pid), emu.GetItems(pid)); if (b != null) { FhirHelper.WriteResource(pid, b, outputDirectory, xml); } } }
private static Bundle MakeBundle(System.Collections.Generic.List <string> rx, System.Collections.Generic.List <System.Collections.Generic.List <string> > items) { Bundle b = new Bundle { Id = FhirHelper.MakeId(), Type = Bundle.BundleType.Message }; ParticipantMaker author = new ParticipantMaker(); author.Make(EMUData.AUTHORROLEPROFILE, rx); GetParticipantIdentifiers(author); Patient p = MakePatient(rx); if (resdir != null) { if (!practitioners.ContainsKey(currentPractitioner)) { FhirHelper.WriteResource(null, author.Practitioner, resdir, xml); practitioners.Add(currentPractitioner, author.Practitioner.Id); } else { author.Practitioner.Id = practitioners[currentPractitioner]; } if (!organisations.ContainsKey(currentOrganisation)) { FhirHelper.WriteResource(null, author.Organisation, resdir, xml); organisations.Add(currentOrganisation, author.Organisation.Id); } else { author.Organisation.Id = organisations[currentOrganisation]; } if (!roles.ContainsKey(currentRole)) { FhirHelper.WriteResource(null, author.Role, resdir, xml); roles.Add(currentRole, author.Role.Id); } else { author.Role.Id = roles[currentRole]; } if (!patients.ContainsKey(currentNhsNumber)) { FhirHelper.WriteResource(null, p, resdir, xml); patients.Add(currentNhsNumber, p.Id); } else { p.Id = patients[currentNhsNumber]; } } MessageHeader header = MakeMessageHeader(author); FhirHelper.AddEntryToBundle(b, header); FhirHelper.AddEntryToBundle(b, p); FhirHelper.AddEntryToBundle(b, author.Practitioner); FhirHelper.AddEntryToBundle(b, author.Organisation); FhirHelper.AddEntryToBundle(b, author.Role); ResourceReference nominatedPharmacy = GetNominatedPharmacyReference(rx); foreach (System.Collections.Generic.List <string> item in items) { MedicationRequest m = MakeMedicationRequest(p, rx, item, nominatedPharmacy, author); if (m != null) { FhirHelper.AddEntryToBundle(b, m); header.Focus.Add(FhirHelper.MakeInternalReference(m)); FhirHelper.WriteResource(null, m, resdir, xml); } } header.Focus.Add(FhirHelper.MakeInternalReference(p)); header.Focus.Add(FhirHelper.MakeInternalReference(author.Role)); return(b); }