Package uk.nhs.interoperability.payloads.childscreeningv2

Examples of uk.nhs.interoperability.payloads.childscreeningv2.ClinicalDocument


import uk.nhs.interoperability.payloads.vocabularies.internal.TelecomUseType;

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());
   
    TextSection ts1 = createTextSection_Guardian(childScreeningFields);
    if (ts1 != null) template.addTextSections(new TextSections(ts1));
   
    TextSection ts2 = createTextSection_NewBornBirthDetails(childScreeningFields);
    if (ts2 != null) template.addTextSections(new TextSections(ts2));

   
   
    return template;
  }
View Full Code Here


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

      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);
          }
        }
      }
View Full Code Here

      // 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
View Full Code Here

   
    // ==== Now create the text sections ====
    template.setMainDocumentSectionID(CDAUUID.generateUUIDString());
   
    TextSection ts1 = createTextSection_Guardian(childScreeningFields);
    if (ts1 != null) template.addTextSections(new TextSections(ts1));
   
    TextSection ts2 = createTextSection_NewBornBirthDetails(childScreeningFields);
    if (ts2 != null) template.addTextSections(new TextSections(ts2));

   
   
    return template;
  }
View Full Code Here

 
  @Test
  public void testCreateDocumentMissingMandatoryFields() {
    EndOfLifeCareISBFields fields = new EndOfLifeCareISBFields();
    try {
      ClinicalDocument doc = EndOfLifeCareDocumentCreationHelper.createDocument(fields);
      fail("Expected exception was not thrown to list missing mandatory fields");
    } catch (MissingMandatoryFieldException e) {
      System.out.println(e.toString());
      // We expect 18 missing mandatory fields to be reported
      assertEquals(19, e.getMissingFields().size());
View Full Code Here

  @Test
  public void testCreateDocumentMinimal() {
    super.init("endoflifecare/", "EOLCHelper-serialiseMinimal", "EoLC Helper: Minimal Serialise", "This uses the EOLC Helper class to generate a full end of life care CDA document with a minimal set of fields, and serialises to a CDA document, which is compared with an expected document example.");
    try {
      // Use the helper to create the document
      ClinicalDocument doc = EndOfLifeCareDocumentCreationHelper.createDocument(minimal);
      // Serialise to a CDA XML Document
      String xml = doc.serialise();
     
      // Generate the rendered version
      super.render(xml);
     
      content = content.replaceAll("#TESTRESULT#", "<div class='pass'>PASS: Successfully created minimal CDA document</div>");
View Full Code Here

  @Test
  public void testCreateDocumentFull() {
    super.init("endoflifecare/", "EOLCHelper-serialiseFull", "EoLC Helper: Full Serialise", "This uses the EOLC Helper class to generate a full end of life care CDA document with a full set of fields, and serialises to a CDA document, which is compared with an expected document example.");
    try {
      // Use the helper to create the document
      ClinicalDocument doc = EndOfLifeCareDocumentCreationHelper.createDocument(full);
      // Serialise to a CDA XML Document
      String xml = doc.serialise();
      System.out.println(xml);
     
      // Generate the rendered version
      super.render(xml);
     
View Full Code Here

  @Test
  public void testMinimalDocumentSchemaCheck() {
    super.init("endoflifecare/", "EOLCHelper-MinimalSchemaCheck", "EoLC Helper: Minimal Schema Check", "This uses the EOLC Helper class to generate a full end of life care CDA document with a minimal set of fields, and serialises to a CDA document, which is validated against the on-the-wire schema.");
    try {
      // Use the helper to create the document
      ClinicalDocument doc = EndOfLifeCareDocumentCreationHelper.createDocument(minimal);
      // Serialise to a CDA XML Document
      String xml = doc.serialise();
      // Now check it is valid according to the schema
      testAgainstSchema(
          PropertyReader.getProperty("endoflifecareSchemaPath")+"POCD_MT000002UK01.xsd",
          xml);
     
View Full Code Here

  @Test
  public void testMinimalDocumentTemplatedSchemaCheck() {
    super.init("endoflifecare/", "EOLCHelper-MinimalTemplatedCheck", "EoLC Helper: Minimal Templated Check", "This uses the EOLC Helper class to generate a full end of life care CDA document with a minimal set of fields, and serialises to a CDA document, transforms it to templated format, which is validated against the templated schema.");
    try {
      // Use the helper to create the document
      ClinicalDocument doc = EndOfLifeCareDocumentCreationHelper.createDocument(minimal);
      // Serialise to a CDA XML Document
      String xml = doc.serialise();
      // And then transform and re-test against templated schema
      testAgainstTemplatedSchema(
          PropertyReader.getProperty("endoflifecareSchemaPath")+"POCD_MT021001GB01.xsd",
          xml);
     
View Full Code Here

TOP

Related Classes of uk.nhs.interoperability.payloads.childscreeningv2.ClinicalDocument

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.