Package uk.nhs.interoperability.payloads.helpers

Source Code of uk.nhs.interoperability.payloads.helpers.ChildScreeningDocumentCreationHelper

/*
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package uk.nhs.interoperability.payloads.helpers;

import java.util.Date;
import java.util.List;

import uk.nhs.interoperability.payloads.DateValue;
import uk.nhs.interoperability.payloads.childscreeningv2.ClinicalDocument;
import uk.nhs.interoperability.payloads.childscreeningv2.CodedSections;
import uk.nhs.interoperability.payloads.childscreeningv2.InformationOnlyRecipient;
import uk.nhs.interoperability.payloads.childscreeningv2.PrimaryRecipient;
import uk.nhs.interoperability.payloads.childscreeningv2.TextSections;
import uk.nhs.interoperability.payloads.commontypes.Address;
import uk.nhs.interoperability.payloads.commontypes.ConsentID;
import uk.nhs.interoperability.payloads.commontypes.OrgID;
import uk.nhs.interoperability.payloads.commontypes.PatientIDWithTraceStatuses;
import uk.nhs.interoperability.payloads.commontypes.PersonID;
import uk.nhs.interoperability.payloads.commontypes.PersonName;
import uk.nhs.interoperability.payloads.commontypes.RoleID;
import uk.nhs.interoperability.payloads.commontypes.Telecom;
import uk.nhs.interoperability.payloads.exceptions.MissingMandatoryFieldException;
import uk.nhs.interoperability.payloads.templates.AuthorPersonUniversal;
import uk.nhs.interoperability.payloads.templates.BloodSpotScreening;
import uk.nhs.interoperability.payloads.templates.ChildPatientOrganisationPartOf;
import uk.nhs.interoperability.payloads.templates.ChildPatientUniversal;
import uk.nhs.interoperability.payloads.templates.Consent;
import uk.nhs.interoperability.payloads.templates.CustodianOrganizationUniversal;
import uk.nhs.interoperability.payloads.templates.EoLCarePlan;
import uk.nhs.interoperability.payloads.templates.Guardian;
import uk.nhs.interoperability.payloads.templates.GuardianPerson;
import uk.nhs.interoperability.payloads.templates.NewBornBirthDetails;
import uk.nhs.interoperability.payloads.templates.NewBornHearingScreening;
import uk.nhs.interoperability.payloads.templates.NewBornPhysicalExamination;
import uk.nhs.interoperability.payloads.templates.Recipient;
import uk.nhs.interoperability.payloads.templates.RecipientPersonUniversal;
import uk.nhs.interoperability.payloads.templates.Section2;
import uk.nhs.interoperability.payloads.templates.Section3;
import uk.nhs.interoperability.payloads.templates.TextSection;
import uk.nhs.interoperability.payloads.util.CDAUUID;
import uk.nhs.interoperability.payloads.vocabularies.generated.AudiologyTestingOutcomeStatus;
import uk.nhs.interoperability.payloads.vocabularies.generated.BSLaboratoryInterpretationCode;
import uk.nhs.interoperability.payloads.vocabularies.generated.BSScreeningLocStatus;
import uk.nhs.interoperability.payloads.vocabularies.generated.BSScreeningStatusSubCodes;
import uk.nhs.interoperability.payloads.vocabularies.generated.CFScreeningResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.CHTScreeningResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.EyesExaminationResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.HeartExaminationResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.HipsExaminationResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.HipsExpertManagementPlanType;
import uk.nhs.interoperability.payloads.vocabularies.generated.HipsUltraSoundOutcomeDecision;
import uk.nhs.interoperability.payloads.vocabularies.generated.MCADDScreeningResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.NewBornHearingScreeningOutcomeSnCT;
import uk.nhs.interoperability.payloads.vocabularies.generated.PKUScreeningResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.SCDScreeningResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.TestesExaminationResult;
import uk.nhs.interoperability.payloads.vocabularies.generated.x_BasicConfidentialityKind;
import uk.nhs.interoperability.payloads.vocabularies.internal.AddressType;
import uk.nhs.interoperability.payloads.vocabularies.internal.DatePrecision;
import uk.nhs.interoperability.payloads.vocabularies.internal.NHSNumberTraceStatus;
import uk.nhs.interoperability.payloads.vocabularies.internal.NullFlavour;
import uk.nhs.interoperability.payloads.vocabularies.internal.OrgIDType;
import uk.nhs.interoperability.payloads.vocabularies.internal.PatientIDType;
import uk.nhs.interoperability.payloads.vocabularies.internal.PersonIDType;
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;
  }

  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();
   
    String idType = null;
    if (fields.getPatientNHSNoTraceStatus().sameAs(NHSNumberTraceStatus.Traced)) {
      idType = PatientIDType.VerifiedNHSNumber.code;
    } else {
      idType = PatientIDType.UnverifiedNHSNumber.code;
    }
   
    template.addPatientID(new PatientIDWithTraceStatuses()
                .setPatientID(fields.getPatientNHSNo())
                .setPatientIDType(idType)
                .setNHSNoTraceStatus(fields.getPatientNHSNoTraceStatus().code));
   
    if (fields.getPatientAddress() != null) {
      template.addAddress(fields.getPatientAddress());
    }
    template.addName(fields.getPatientName());
    template.setGender(fields.getPatientGender());
    template.setDateOfBirth(fields.getPatientBirthDate());
   
    // Guardian
    if (guardian) {
      Guardian guardianFields = new Guardian();
     
      String guardianIdType = null;
      if (fields.getGuardianNHSNoTraceStatus().sameAs(NHSNumberTraceStatus.Traced)) {
        guardianIdType = PatientIDType.VerifiedNHSNumber.code;
      } else {
        guardianIdType = PatientIDType.UnverifiedNHSNumber.code;
      }
      guardianFields.addId(new PatientIDWithTraceStatuses()
                    .setPatientID(fields.getGuardianNHSNo())
                    .setPatientIDType(guardianIdType)
                    .setNHSNoTraceStatus(fields.getGuardianNHSNoTraceStatus().code));
      guardianFields.setGuardianDetails(new GuardianPerson().setGuardianName(fields.getGuardianName()));
      guardianFields.setRole(fields.getGuardianRole());
     
      if (guardianAddress) {
        guardianFields.addAddress(fields.getGuardianAddress());
      }
      if (guardianTelephone) {
        guardianFields.addTelephoneNumber(new Telecom()
                      .setTelecom("tel:" + fields.getGuardianTelephone())
                      .setTelecomType(TelecomUseType.HomeAddress.code));
      }
      template.addGuardian(guardianFields);
    }
   
    // Provider Organisation
    if (provider) {
       template.setOrganisationId(new OrgID(OrgIDType.ODSOrgID.code, fields.getProviderOrganisationODSID()));
      template.setOrganisationName(fields.getProviderOrganisation());
      template.setOrganisationType(fields.getProviderOrganisationType());
     
      if (providerOrganisationTelephone) {
        template.addOrganisationTelephone(new Telecom()
                          .setTelecom("tel:" + fields.getProviderOrganisationTelephone())
                          .setTelecomType(TelecomUseType.WorkPlace.code));
      }
     
      if (providerOrganisationAddress) {
        template.setOrganisationAddress(fields.getProviderOrganisationAddress());
      }
     
      if (providerParentOrganisationODSID) {
        template.addOrganisationPartOf(new ChildPatientOrganisationPartOf()
                          .addOrganisationId(new OrgID(OrgIDType.ODSOrgID.code,
                                          fields.getProviderParentOrganisationODSID())));
      }
    }
    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
    template.addId(new PersonID()
             .setType(PersonIDType.SDSID.code)
             .setID(fields.getDocumentAuthorSDSID()));
   
    // Author Job Role
     template.setJobRoleName(fields.getDocumentAuthorRole());
    
     // Author Address
     if (fields.getDocumentAuthorAddress() != null) {
       Address add = fields.getDocumentAuthorAddress();
       add.setAddressUse(AddressType.WorkPlace.code);
       template.addAddress(add);
     }
    
     // Author telephone number
     if (fields.getDocumentAuthorTelephone() != null) {
       template.addTelephoneNumber(new Telecom("tel:" + fields.getDocumentAuthorTelephone()));
     }
    
     // Author Name
     template.setName(fields.getDocumentAuthorName());
    
     // Author ORG ID
    template.setOrganisationId(new OrgID()
                  .setID(fields.getDocumentAuthorOrganisationODSID())
                  .setType(OrgIDType.ODSOrgID.code));
   
    // Author ORG Name
    template.setOrganisationName(fields.getDocumentAuthorOrganisationName());
   
    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();
   
    // Custodian Org ID
    template.setId(new OrgID(OrgIDType.ODSOrgID.code, fields.getCustodianOrganisationODSID()));
   
    // Custodian Org Name
    template.setName(fields.getCustodianOrganisation());
   
    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));
    // recipientName
    template.setName(recipient.getRecipientName());
    // recipientAddress
    if (recipient.getRecipientAddress() != null) {
      template.setAddress(recipient.getRecipientAddress());
    }
    // recipientTelephone
     if (recipient.getRecipientTelephone() != null) {
       template.addTelephoneNumber(new Telecom("tel:" + recipient.getRecipientTelephone()));
     }
    // recipientJobRole
     if (recipient.getRecipientJobRole() != null) {
       template.setJobRoleName(recipient.getRecipientJobRole());
     }
    // recipientODSCode
     template.setOrgId(new OrgID()
                 .setID(recipient.getRecipientODSCode())
                 .setType(OrgIDType.ODSOrgID.code));
    // recipientOrganisationName
     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;
    }
   
    BloodSpotScreening template = new BloodSpotScreening();
   
    template.setId(CDAUUID.generateUUIDString());
    template.setEffectiveTime(fields.getDateOfBloodSpotScreening());
    // Performer
    template.setSampleCollectedTime(fields.getBloodSpotSampleCollectedTime());
    template.addPerformerPersonId(new PersonID().setID(fields.getBloodSpotPerformerPersonSDSID()).setType(PersonIDType.SDSID.code));
    template.setPerformerPersonName(fields.getBloodSpotPerformerPersonName());
    template.setPerformerOrgId(new OrgID()
                      .setID(fields.getBloodSpotPerformerOrganisationODSID())
                      .setType(OrgIDType.ODSOrgID.code));
    template.setPerformerOrgName(fields.getBloodSpotPerformerOrganisationName());
    // Lab
    template.setTimeReceivedAtLab(fields.getBloodSpotTimeReceivedAtLab());
    template.setLabOrganisationId(new OrgID()
                      .setID(fields.getBloodSpotLabOrganisationODSID())
                      .setType(OrgIDType.ODSOrgID.code));
    template.setLabOrganisationDescription(fields.getBloodSpotLabOrganisationName());
   
    // Screening results
    template.setPKUScreeningValue(fields.getPKUScreeningValue());
    if (fields.getLaboratoryConfirmPKUasCorrect()) {
      template.setPKUBSLaboratoryInterpretationCode(BSLaboratoryInterpretationCode._ReevaluatedResultLaboratoryConfirmasCorrect);
    }
    template.setPKUScreeningSubStatus(fields.getPKUScreeningSubStatus());
    template.setPKUReasonText(fields.getPKUReasonText());
    template.setPKUSupplementaryText(fields.getPKUSupplementaryText());
   
    template.setSCDScreeningValue(fields.getSCDScreeningValue());
    if (fields.getLaboratoryConfirmSCDasCorrect()) {
      template.setSCDBSLaboratoryInterpretationCode(BSLaboratoryInterpretationCode._ReevaluatedResultLaboratoryConfirmasCorrect);
    }
    template.setSCDScreeningSubStatus(fields.getSCDScreeningSubStatus());
    template.setSCDReasonText(fields.getSCDReasonText());
    template.setSCDSupplementaryText(fields.getSCDSupplementaryText());
   
    template.setCFScreeningValue(fields.getCFScreeningValue());
    if (fields.getLaboratoryConfirmCFasCorrect()) {
      template.setCFBSLaboratoryInterpretationCode(BSLaboratoryInterpretationCode._ReevaluatedResultLaboratoryConfirmasCorrect);
    }
    template.setCFScreeningSubStatus(fields.getCFScreeningSubStatus());
    template.setCFReasonText(fields.getCFReasonText());
    template.setCFSupplementaryText(fields.getCFSupplementaryText());
   
    template.setCHTScreeningValue(fields.getCHTScreeningValue());
    if (fields.getLaboratoryConfirmCHTasCorrect()) {
      template.setCHTBSLaboratoryInterpretationCode(BSLaboratoryInterpretationCode._ReevaluatedResultLaboratoryConfirmasCorrect);
    }
    template.setCHTScreeningSubStatus(fields.getCHTScreeningSubStatus());
    template.setCHTReasonText(fields.getCHTReasonText());
    template.setCHTSupplementaryText(fields.getCHTSupplementaryText());
   
    template.setMCADDScreeningValue(fields.getMCADDScreeningValue());
    if (fields.getLaboratoryConfirmMCADDasCorrect()) {
      template.setMCADDBSLaboratoryInterpretationCode(BSLaboratoryInterpretationCode._ReevaluatedResultLaboratoryConfirmasCorrect);
    }
    template.setMCADDScreeningSubStatus(fields.getMCADDScreeningSubStatus());
    template.setMCADDReasonText(fields.getMCADDReasonText());
    template.setMCADDSupplementaryText(fields.getMCADDSupplementaryText());
   
    // Other observations
    template.setScreeningLocationStatus(fields.getScreeningLocationStatus());
    template.setLaboratoryCardSerialNumber(fields.getLaboratoryCardSerialNumber());
    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;
    }
   
    NewBornBirthDetails template = new NewBornBirthDetails();

    template.setId(CDAUUID.generateUUIDString());
    template.setEffectiveTime(fields.getDateBirthDetailsRecorded());
    template.setGestationalAgeInWeeks(fields.getGestationalAgeInWeeks());
    if (fields.getBirthOrder() != null) {
      template.setBirthOrder(Integer.toString(fields.getBirthOrder()));
    }
    if (fields.getNoOfFoetusInConfinement() != null) {
      template.setNoOfFoetusInConfinement(Integer.toString(fields.getNoOfFoetusInConfinement()));
    }
    template.setBirthWeightInGrams(fields.getBirthWeightInGrams());
   
    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;
    }
   
    NewBornHearingScreening template = new NewBornHearingScreening();
    template.setId(CDAUUID.generateUUIDString());
    template.setScreeningOutcome(fields.getHearingScreeningOutcome());
    template.setAudiologyTestFinding(fields.getAudiologyTestFinding());
    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;
    }
   
    NewBornPhysicalExamination template = new NewBornPhysicalExamination();
    template.setId(CDAUUID.generateUUIDString());
    template.setEffectiveTime(fields.getDateOfPhysicalExamination());
    if (fields.getGestationalAgeInDays() != null) {
      template.setGestationalAgeInDays(Integer.toString(fields.getGestationalAgeInDays()));
    }
    template.setHipsExamination(fields.getHipsExamination());
    template.setUltraSoundDecision(fields.getUltraSoundDecision());
    template.setExpertManagementPlan(fields.getExpertManagementPlan());
    template.setHeartExamination(fields.getHeartExamination());
    template.setEyesExamination(fields.getEyesExamination());
    template.setTestesExamination(fields.getTestesExamination());
    return template;
  }
 
  public static TextSection createTextSection_Guardian(ChildScreeningFields fields) {
    TextSection template = new TextSection();
    template.setSectionId(CDAUUID.generateUUIDString());
    template.setTitle("Guardian Details");
    template.setText("<table width=\"100%\"><tbody>"
        + "<tr align=\"left\" valign=\"top\"><td>Relationship</td><td>" + fields.getGuardianRole().displayName + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td>NHS Number</td><td>" + fields.getGuardianNHSNo() + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td>Name</td><td>" + HumanReadableFormatter.makeHumanReadablePersonName(fields.getGuardianName()) + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td>Address</td><td>" + HumanReadableFormatter.makeHumanReadableAddress(fields.getGuardianAddress(), "<br/>") + "</td></tr>"
        + "</tbody></table>");
    return template;
  }
 
  public static TextSection createTextSection_NewBornBirthDetails(ChildScreeningFields fields) {
    TextSection template = new TextSection();
    template.setSectionId(CDAUUID.generateUUIDString());
    template.setTitle("New Born Birth Details");
    template.setText("<table width=\"100%\"><tbody>"
        + "<tr align=\"left\" valign=\"top\"><td><content ID=\"a1\">Gestational age</content></td><td>" + fields.getGestationalAgeInWeeks() + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td><content ID=\"a2\">Birth order</content></td><td>" + fields.getBirthOrder() + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td><content ID=\"a3\">Number of births in confinement</content></td><td>" + fields.getNoOfFoetusInConfinement() + "</td></tr>"
        + "<tr align=\"left\" valign=\"top\"><td><content ID=\"a4\">Birth weight</content></td><td>" + fields.getBirthWeightInGrams() + " grams</td></tr>"
        + "</tbody></table>");
    return template;
  }
 
}
TOP

Related Classes of uk.nhs.interoperability.payloads.helpers.ChildScreeningDocumentCreationHelper

TOP
Copyright © 2018 www.massapi.com. 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.