public class EndOfLifeCareDocumentCreationCDGRSHelper {
public static ClinicalDocument createDocument(EndOfLifeCareISBFields isbFields) throws MissingMandatoryFieldException {
ClinicalDocument template = new ClinicalDocument();
MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
DateValue currentDateTime = new DateValue(new Date(), DatePrecision.Minutes);
// ==== We will assume some things and set them accordingly ====
template.setDocumentId(CDAUUID.generateUUIDString());
template.setDocumentTitle("End of Life Care Coordination Summary");
template.setConfidentialityCode(x_BasicConfidentialityKind._N);
// If no record effective date/time specified, assume the current date/time
if (isbFields.getDocumentCreationDate() == null) {
template.setEffectiveTime(currentDateTime);
} else {
template.setEffectiveTime(isbFields.getDocumentCreationDate());
}
// If no document set ID provided, generate a new one
if (isbFields.getDocumentSetId() != null) {
template.setDocumentSetId(isbFields.getDocumentSetId());
} else {
template.setDocumentSetId(CDAUUID.generateUUIDString());
}
// Version defaults to 1 unless set to a different integer value
template.setDocumentVersionNumber(String.valueOf(isbFields.getDocumentVersionNumber()));
// Patient
try {
PatientUniversal patient = createPatient(isbFields);
template.setPatient(patient);
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Author
if (isbFields.getDocumentAuthoredTime() == null) {
template.setTimeAuthored(currentDateTime);
} else {
template.setTimeAuthored(isbFields.getDocumentAuthoredTime());
}
try {
AuthorPersonUniversal author = createAuthor(isbFields);
template.setAuthor(author);
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Custodian (Organisation hosting the EPaCCS)
try {
CustodianOrganizationUniversal custodian = createCustodian(isbFields);
template.setCustodianOrganisation(custodian);
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Recipients - this is not part of the core ISB data set, and may not be
// relevant depending on how the EPaCCS works (e.g. send document on-demand), so
// we won't do anything with recipients in this helper. These can easily be added
// to the document afterwards by calling the relevant methods.
// ==== Now create the coded sections ====
EoLCarePlan carePlan;
AdvanceDecisionToRefuseTreatment adrt;
AnticipatoryMedicineBoxIssueProcedure ambox;
DNACPRDecisionbySeniorResponsibleClinician dnacpr;
PrognosisAwareness prognosis;
AuthoritytoLastingPowerofAttorney lpa;
// End of Life Care Plan
try {
carePlan = createEoLCarePlan(isbFields);
template.addCodedSections(new CodedSections(carePlan));
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Advance decision to refuse treatment
try {
adrt = createADRT(isbFields);
if (adrt != null) {
template.addCodedSections(new CodedSections(adrt));
}
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Anticipatory medicine box
try {
ambox = createAMBox(isbFields);
if (ambox != null) {
template.addCodedSections(new CodedSections(ambox));
}
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// DNACPR Decision
try {
dnacpr = createDNACPR(isbFields);
if (dnacpr != null) {
template.addCodedSections(new CodedSections(dnacpr));
}
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Main informal carer awareness of prognosis
try {
prognosis = createPrognosisAwareness(isbFields);
if (prognosis != null) {
template.addCodedSections(new CodedSections(prognosis));
}
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Authority to Lasting Power of Attorney
try {
lpa = createLPA(isbFields);
if (lpa != null) {
template.addCodedSections(new CodedSections(lpa));
}
} catch (MissingMandatoryFieldException e) {
missingFields.addMissingFields(e);
}
// Additional mandatory field checks for text sections
if (isbFields.getPrimaryEOLCDiagnosis() == null) {
missingFields.addMissingField("PrimaryEOLCDiagnosis", "A primary EOLC Diagnosis must be provided");
}
// We have done all the checks on mandatory fields, so if there are any
// errors, throw them up to the caller
if (missingFields.hasEntries()) {
throw missingFields;
}
// ==== Now create the text sections ====
template.setMainDocumentSectionID(CDAUUID.generateUUIDString());