Package uk.nhs.interoperability.payloads.exceptions

Examples of uk.nhs.interoperability.payloads.exceptions.MissingMandatoryFieldException


public class ChildScreeningDocumentCreationHelper {

  public static ClinicalDocument createDocument(ChildScreeningFields childScreeningFields) 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.setConfidentialityCode(x_BasicConfidentialityKind._N);
   
    // If no record effective date/time specified, assume the current date/time
    if (childScreeningFields.getDocumentCreationDate() == null) {
      template.setEffectiveTime(currentDateTime);
    } else {
      template.setEffectiveTime(childScreeningFields.getDocumentCreationDate());
    }
   
    // If no document set ID provided, generate a new one
    if (childScreeningFields.getDocumentSetId() != null) {
      template.setDocumentSetId(childScreeningFields.getDocumentSetId());
    } else {
      template.setDocumentSetId(CDAUUID.generateUUIDString());
    }
   
    // Version defaults to 1 unless set to a different integer value
    template.setDocumentVersionNumber(String.valueOf(childScreeningFields.getDocumentVersionNumber()));
   
   
    // Child Patient
    try {
      ChildPatientUniversal patient = createPatient(childScreeningFields);
      template.setChildPatient(patient);
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Author
    if (childScreeningFields.getDocumentAuthoredTime() == null) {
      template.setTimeAuthored(currentDateTime);
    } else {
      template.setTimeAuthored(childScreeningFields.getDocumentAuthoredTime());
    }
   
    try {
      AuthorPersonUniversal author = createAuthor(childScreeningFields);
      template.setAuthor(author);
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Custodian (Organisation hosting the EPaCCS)
    try {
      CustodianOrganizationUniversal custodian = createCustodian(childScreeningFields);
      template.setCustodianOrganisation(custodian);
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Recipients
   
    // Having at least one recipient is mandatory
    if (childScreeningFields.getRecipients()==null) {
      missingFields.addMissingField("recipients", "At least one recipient must be provided");
    } else if (childScreeningFields.getRecipients().size()==0) {
      missingFields.addMissingField("recipients", "At least one recipient must be provided");
    } else {
      // Primary Recipients
      for (DocumentRecipient recipient : childScreeningFields.getRecipients()) {
        try {
          Recipient r = createRecipient(recipient);
          template.addPrimaryRecipients(
                new PrimaryRecipient().setRecipient(r));
        } catch (MissingMandatoryFieldException e) {
          missingFields.addMissingFields(e);
        }
      }
      // Copy Recipients
      if (childScreeningFields.getCopyRecipients() != null) {
        for (DocumentRecipient recipient : childScreeningFields.getCopyRecipients()) {
          try {
            Recipient r = createRecipient(recipient);
            template.addInformationOnlyRecipients(
                  new InformationOnlyRecipient().setRecipient(r));
          } catch (MissingMandatoryFieldException e) {
            missingFields.addMissingFields(e);
          }
        }
      }
    }
   
    // Consent
    if (childScreeningFields.getConsent() != null) {
      template.setAuthorizingConsent(new Consent()
                          .setConsentCode(childScreeningFields.getConsent())
                          .addID(new ConsentID(CDAUUID.generateUUIDString())));
    }

    // ==== Now create the coded sections ====
   
    // Blood Spot Screening
    try {
      BloodSpotScreening bloodspot = createBloodSpotScreening(childScreeningFields);
      if (bloodspot != null) {
        template.addCodedSections(new CodedSections(bloodspot));
      }
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // New Born Birth Details
    try {
      NewBornBirthDetails birthdetails = createBirthDetails(childScreeningFields);
      if (birthdetails != null) {
        template.addCodedSections(new CodedSections(birthdetails));
      }
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Hearing Screening
    try {
      NewBornHearingScreening hearing = createHearingScreening(childScreeningFields);
      if (hearing != null) {
        template.addCodedSections(new CodedSections(hearing));
      }
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Hearing Screening
    try {
      NewBornPhysicalExamination physical = createPhysicalExam(childScreeningFields);
      if (physical != null) {
        template.addCodedSections(new CodedSections(physical));
      }
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // 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());
View Full Code Here


   
    return template;
  }

  public static ChildPatientUniversal createPatient(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
   
    // Null checks for mandatory fields
    if (fields.getPatientNHSNoTraceStatus() == null) {
      missingFields.addMissingField("PatientNHSNoTraceStatus", "The tracing status for the NHS number must be provided");
    }
    if (fields.getPatientNHSNo() == null) {
      missingFields.addMissingField("PatientNHSNo", "The patient's NHS number must be provided");
    }
    if (fields.getPatientName() == null) {
      missingFields.addMissingField("PatientName", "The patient's name must be provided");
    }
    if (fields.getPatientGender() == null) {
      missingFields.addMissingField("PatientGender", "The patient's gender must be provided");
    }
    if (fields.getPatientBirthDate() == null) {
      missingFields.addMissingField("PatientBirthDate", "The patient's date of birth must be provided");
    }
   
    // Check if a guardian has been provided, and if so, check all the fields are there
    boolean guardianName = fields.getGuardianName() != null;
    boolean guardianNHSNo = fields.getGuardianNHSNo() != null;
    boolean guardianNHSNoTraceStatus = fields.getGuardianNHSNoTraceStatus() != null;
    boolean guardianAddress = fields.getGuardianAddress() != null;
    boolean guardianTelephone = fields.getGuardianTelephone() != null;
    boolean guardianRole = fields.getGuardianRole() != null;
    boolean guardian = (guardianName || guardianNHSNo || guardianNHSNoTraceStatus || guardianAddress || guardianTelephone || guardianRole);
    if (guardian) {
      if (!guardianName) {
        missingFields.addMissingField("GuardianName", "When a guardian is specified, a name must be included");
      }
      if (!guardianNHSNo) {
        missingFields.addMissingField("GuardianNHSNo", "When a guardian is specified, an NHS number must be included");
      }
      if (!guardianNHSNoTraceStatus) {
        missingFields.addMissingField("GuardianNHSNoTraceStatus", "When a guardian is specified, an NHS number trace status must be included");
      }
      if (!guardianRole) {
        missingFields.addMissingField("GuardianRole", "When a guardian is specified, a guardian role must be included");
      }
    }
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    // Check if a provider Org is provided
    boolean providerOrganisationODSID = fields.getProviderOrganisationODSID() != null;
    boolean providerOrganisation = fields.getProviderOrganisation() != null;
    boolean providerOrganisationAddress = fields.getProviderOrganisationAddress() != null;
    boolean providerOrganisationTelephone = fields.getProviderOrganisationTelephone() != null;
    boolean providerOrganisationType = fields.getProviderOrganisationType() != null;
    boolean providerParentOrganisationODSID = fields.getProviderParentOrganisationODSID() != null;
    boolean provider = (providerOrganisationODSID || providerOrganisation || providerOrganisationAddress || providerOrganisationTelephone || providerOrganisationType || providerParentOrganisationODSID);
    if (provider) {
      if (!providerOrganisationODSID) {
        missingFields.addMissingField("ProviderOrganisationODSID", "When a provider organisation is specified for a child patient, an ODS code must be included");
      }
      if (!providerOrganisation) {
        missingFields.addMissingField("ProviderOrganisation", "When a provider organisation is specified for a child patient, an Org Name must be included");
      }
      if (!providerOrganisationType) {
        missingFields.addMissingField("ProviderOrganisationType", "When a provider organisation is specified for a child patient, a provider org type must be included");
      }
    }
   
    ChildPatientUniversal template = new ChildPatientUniversal();
   
View Full Code Here

    }
    return template;
  }
 
  public static AuthorPersonUniversal createAuthor(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
   
    // Null checks for mandatory fields
    if (fields.getDocumentAuthorSDSID() == null) {
      missingFields.addMissingField("DocumentAuthorSDSID", "The SDS ID of the document author must be provided");
    }
    if (fields.getDocumentAuthorRole() == null) {
      missingFields.addMissingField("DocumentAuthorRole", "The job role of the document author must be provided");
    }
    if (fields.getDocumentAuthorName() == null) {
      missingFields.addMissingField("DocumentAuthorName", "The name of the document author must be provided");
    }
    if (fields.getDocumentAuthorOrganisationODSID() == null) {
      missingFields.addMissingField("DocumentAuthorOrganisationODSID", "The ID of the organisation the document author belongs to must be provided");
    }
    if (fields.getDocumentAuthorOrganisationName() == null) {
      missingFields.addMissingField("DocumentAuthorOrganisationName", "The name of the organisation the document author belongs to must be provided");
    }
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    AuthorPersonUniversal template = new AuthorPersonUniversal();
     // Author SID ID
View Full Code Here

   
    return template;
  }
 
  public static CustodianOrganizationUniversal createCustodian(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
    if (fields.getCustodianOrganisationODSID() == null) {
      missingFields.addMissingField("CustodianOrganisationODSID", "The ODS ID of the custodian organisation must be provided");
    }
    if (fields.getCustodianOrganisation() == null) {
      missingFields.addMissingField("CustodianOrganisation", "The name of the custodian organisation must be provided");
    }
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    CustodianOrganizationUniversal template = new CustodianOrganizationUniversal();
   
View Full Code Here

   
    return template;
  }
 
  public static Recipient createRecipient(DocumentRecipient recipient) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
    if (recipient.getRecipientName() == null) {
      missingFields.addMissingField("recipientName", "The name of the recipient must be provided");
    }
    if (recipient.getRecipientODSCode() == null) {
      missingFields.addMissingField("recipientODSCode", "The ODS Code for the organisation of the recipient must be provided");
    }
    if (recipient.getRecipientOrganisationName() == null) {
      missingFields.addMissingField("recipientOrganisationName", "The organisation name for the recipient must be provided");
    }
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
    RecipientPersonUniversal template = new RecipientPersonUniversal();
    // ID (NULL)
    template.addId(new RoleID().setNullFlavour(NullFlavour.NA.code));
View Full Code Here

     template.setOrgName(recipient.getRecipientOrganisationName());
    return template;
  }

  public static BloodSpotScreening createBloodSpotScreening(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
   
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    if (fields.getDateOfBloodSpotScreening() == null) {
      return null;
View Full Code Here

    template.setPreviousLaboratoryCardSerialNumber(fields.getPreviousLaboratoryCardSerialNumber());
    return template;
  }
 
  public static NewBornBirthDetails createBirthDetails(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
   
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    if (fields.getDateBirthDetailsRecorded() == null) {
      return null;
View Full Code Here

   
    return template;
  }
 
  public static NewBornHearingScreening createHearingScreening(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
   
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    if (fields.getHearingScreeningOutcome() == null) {
      return null;
View Full Code Here

    template.setAudiologyReferralTime(fields.getAudiologyReferralTime());
    return template;
  }
 
  public static NewBornPhysicalExamination createPhysicalExam(ChildScreeningFields fields) throws MissingMandatoryFieldException {
    MissingMandatoryFieldException missingFields = new MissingMandatoryFieldException();
    // Null checks for mandatory fields
   
    if (missingFields.hasEntries()) {
      throw missingFields;
    }
   
    if (fields.getDateOfPhysicalExamination() == null) {
      return null;
View Full Code Here

  }
 
  public static ClinicalDocument createDocument(NonCodedCDACommonFields commonFields) 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.setConfidentialityCode(x_BasicConfidentialityKind._N);
   
    // Title
    if (commonFields.getDocumentTitle() != null) {
      template.setDocumentTitle(commonFields.getDocumentTitle());
    } else {
      missingFields.addMissingField("documentTitle", "The document title must be provided");
    }
   
    // Document Type
    if (commonFields.getDocumentType() != null) {
      template.setDocumentType(commonFields.getDocumentType());
    } else {
      missingFields.addMissingField("documentType", "The document type must be provided");
    }
   
    // If no record effective date/time specified, assume the current date/time
    if (commonFields.getDocumentEffectiveTime() == null) {
      template.setEffectiveTime(currentDateTime);
    } else {
      template.setEffectiveTime(commonFields.getDocumentEffectiveTime());
    }
   
    // If no document set ID provided, generate a new one
    if (commonFields.getDocumentSetID() != null) {
      template.setDocumentSetId(commonFields.getDocumentSetID());
    } else {
      template.setDocumentSetId(CDAUUID.generateUUIDString());
    }
   
    // Version defaults to 1 unless set to a different integer value
    template.setDocumentVersionNumber(String.valueOf(commonFields.getDocumentVersionNumber()));
   
    // Patient
    try {
      PatientUniversal patient = createPatient(commonFields);
      template.setPatient(patient);
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Author
    if (commonFields.getTimeAuthored() == null) {
      template.setTimeAuthored(currentDateTime);
    } else {
      template.setTimeAuthored(commonFields.getTimeAuthored());
    }
   
    try {
      AuthorPersonUniversal author = createAuthor(commonFields);
      template.setAuthor(author);
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Data Enterer (optional)
    if (commonFields.getDataEntererName() != null) {
      try {
        template.setDataEnterer(createDataEnterer(commonFields));
      } catch (MissingMandatoryFieldException e) {
        missingFields.addMissingFields(e);
      }
    }
   
    // Custodian
    try {
      template.setCustodianOrganisation(createCustodian(commonFields));
    } catch (MissingMandatoryFieldException e) {
      missingFields.addMissingFields(e);
    }
   
    // Recipients
   
    // Having at least one recipient is mandatory
    if (commonFields.getRecipients()==null) {
      missingFields.addMissingField("recipients", "At least one recipient must be provided");
    } else if (commonFields.getRecipients().size()==0) {
      missingFields.addMissingField("recipients", "At least one recipient must be provided");
    } else {
      // Primary Recipients
      for (DocumentRecipient recipient : commonFields.getRecipients()) {
        try {
          Recipient r = createRecipient(recipient);
          template.addPrimaryRecipients(
                new PrimaryRecipient().setRecipient(r));
        } catch (MissingMandatoryFieldException e) {
          missingFields.addMissingFields(e);
        }
      }
      // Copy Recipients
      if (commonFields.getCopyRecipients() != null) {
        for (DocumentRecipient recipient : commonFields.getCopyRecipients()) {
          try {
            Recipient r = createRecipient(recipient);
            template.addInformationOnlyRecipients(
                  new InformationOnlyRecipient().setRecipient(r));
          } catch (MissingMandatoryFieldException e) {
            missingFields.addMissingFields(e);
          }
        }
      }
    }
   
    // Authenticator
    if (commonFields.getAuthenticatorName() != null) {
      if (commonFields.getAuthenticatedTime() == null) {
        missingFields.addMissingField("authenticatedTime", "The time the document was authenticated must be provided");
      } else {
        template.setTimeAuthenticated(commonFields.getAuthenticatedTime());
      }
      try {
        template.setAuthenticator(createAuthenticator(commonFields));
      } catch (MissingMandatoryFieldException e) {
        missingFields.addMissingFields(e);
      }
    }
   
    // Participants
    if (commonFields.getParticipants() != null) {
      for (NonCodedCDAParticipant participant : commonFields.getParticipants()) {
        if (participant.getParticipantType() == null) {
          missingFields.addMissingField("participantType", "The participant type must be provided");
        }
        try {
          Participant p = createParticipant(participant);
          template.addParticipant((
                new DocumentParticipant()
                      .setParticipant(p)
                      .setParticipantTypeCode(participant.getParticipantType().code)));
        } catch (MissingMandatoryFieldException e) {
          missingFields.addMissingFields(e);
        }
      }
    }
   
    // DocumentationOf
    if (commonFields.getEventCode() != null) {
      try {
        template.addDocumentationOf(new DocumentationOf().setServiceEvent(createServiceEvent(commonFields)));
      } catch (MissingMandatoryFieldException e) {
        missingFields.addMissingFields(e);
      }
    }
   
    // Consent
    if (commonFields.getConsent() != null) {
      template.setAuthorizingConsent(new Consent()
                          .setConsentCode(commonFields.getConsent())
                          .addID(new ConsentID(CDAUUID.generateUUIDString())));
    }
   
    // Encompassing Encounter
    if (commonFields.getEncounterType() != null) {
      template.setEncompassingEncounter(createEncompassingEncounter(commonFields));
    }

    // 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;
    }   
   
    return template;
  }
View Full Code Here

TOP

Related Classes of uk.nhs.interoperability.payloads.exceptions.MissingMandatoryFieldException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.