Search in sources :

Example 1 with Allegation

use of gov.ca.cwds.rest.api.domain.Allegation in project API by ca-cwds.

the class ScreeningToReferralService method processAllegations.

/*
   * CMS Allegation - one for each allegation
   */
private Set<Allegation> processAllegations(ScreeningToReferral scr, String referralId, HashMap<Long, String> perpatratorClient, HashMap<Long, String> victimClient, Set<ErrorMessage> messages) throws ServiceException {
    Set<Allegation> processedAllegations = new HashSet<>();
    Set<Allegation> allegations;
    String victimClientId = "";
    String perpatratorClientId = "";
    allegations = scr.getAllegations();
    if (allegations == null || allegations.isEmpty()) {
        String message = " Referral must have at least one Allegation ";
        ServiceException exception = new ServiceException(message);
        logError(message, exception, messages);
        return processedAllegations;
    }
    for (Allegation allegation : allegations) {
        try {
            if (!ParticipantValidator.isVictimParticipant(scr, allegation.getVictimPersonId())) {
                String message = " Allegation/Victim Person Id does not contain a Participant with a role of Victim ";
                ServiceException exception = new ServiceException(message);
                logError(message, exception, messages);
            }
        } catch (Exception e) {
            logError(e.getMessage(), e, messages);
            // next allegation
            continue;
        }
        if (victimClient.containsKey(allegation.getVictimPersonId())) {
            // this is the legacy Id (CLIENT) of the victime
            victimClientId = victimClient.get(allegation.getVictimPersonId());
        }
        if (allegation.getPerpetratorPersonId() != 0) {
            try {
                if (!ParticipantValidator.isPerpetratorParticipant(scr, allegation.getPerpetratorPersonId())) {
                    String message = " Allegation/Perpetrator Person Id does not contain a Participant with a role of Perpetrator ";
                    ServiceException exception = new ServiceException(message);
                    logError(message, exception, messages);
                }
            } catch (Exception e) {
                logError(e.getMessage(), e, messages);
                // next allegation
                continue;
            }
        }
        if (perpatratorClient.containsKey(allegation.getPerpetratorPersonId())) {
            // this is the legacy Id (CLIENT) of the perpetrator
            perpatratorClientId = perpatratorClient.get(allegation.getPerpetratorPersonId());
        }
        if (victimClientId.isEmpty()) {
            String message = " Victim could not be determined for an allegation ";
            ServiceException exception = new ServiceException(message);
            logError(message, exception, messages);
            // next allegation
            continue;
        }
        if (allegation.getLegacyId() == null || allegation.getLegacyId().isEmpty()) {
            // create an allegation in CMS legacy database
            gov.ca.cwds.rest.api.domain.cms.Allegation cmsAllegation = new gov.ca.cwds.rest.api.domain.cms.Allegation("", DEFAULT_CODE, "", scr.getLocationType(), "", DEFAULT_CODE, allegationTypeCode, scr.getReportNarrative(), "", false, DEFAULT_NON_PROTECTING_PARENT_CODE, false, victimClientId, perpatratorClientId, referralId, DEFAULT_COUNTY_SPECIFIC_CODE, false, DEFAULT_CODE);
            buildErrors(messages, validator.validate(cmsAllegation));
            PostedAllegation postedAllegation = this.allegationService.create(cmsAllegation);
            allegation.setLegacyId(postedAllegation.getId());
            allegation.setLegacySourceTable(ALLEGATION_TABLE_NAME);
            processedAllegations.add(allegation);
        } else {
            gov.ca.cwds.rest.api.domain.cms.Allegation foundAllegation = this.allegationService.find(allegation.getLegacyId());
            if (foundAllegation == null) {
                String message = " Legacy Id on Allegation does not correspond to an existing CMS/CWS Allegation ";
                ServiceException se = new ServiceException(message);
                logError(message, se, messages);
                // next allegation
                continue;
            }
        }
    }
    return processedAllegations;
}
Also used : ParseException(java.text.ParseException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Allegation(gov.ca.cwds.rest.api.domain.Allegation) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) HashSet(java.util.HashSet) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation)

Example 2 with Allegation

use of gov.ca.cwds.rest.api.domain.Allegation in project API by ca-cwds.

the class ScreeningToReferralService method create.

@UnitOfWork(value = "cms")
@Override
public Response create(Request request) {
    ScreeningToReferral screeningToReferral = (ScreeningToReferral) request;
    Set<ErrorMessage> messages = new HashSet<ErrorMessage>();
    verifyReferralHasValidParticipants(screeningToReferral, messages);
    String dateStarted = extractStartDate(screeningToReferral, messages);
    String timeStarted = extractStartTime(screeningToReferral, messages);
    String referralId = createCmsReferral(screeningToReferral, messages, dateStarted, timeStarted);
    createReferralAddress(screeningToReferral, messages);
    Set<Participant> resultParticipants = new HashSet<>();
    HashMap<Long, String> victimClient = new HashMap<>();
    HashMap<Long, String> perpatratorClient = new HashMap<>();
    processParticipants(screeningToReferral, messages, dateStarted, referralId, resultParticipants, victimClient, perpatratorClient);
    Set<CrossReport> resultCrossReports = createCrossReports(screeningToReferral, messages, referralId);
    Set<Allegation> resultAllegations = createAllegations(screeningToReferral, messages, referralId, victimClient, perpatratorClient);
    PostedScreeningToReferral pstr = PostedScreeningToReferral.createWithDefaults(referralId, screeningToReferral, resultParticipants, resultCrossReports, resultAllegations);
    pstr.setMessages(messages);
    return pstr;
}
Also used : HashMap(java.util.HashMap) Participant(gov.ca.cwds.rest.api.domain.Participant) CrossReport(gov.ca.cwds.rest.api.domain.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) Allegation(gov.ca.cwds.rest.api.domain.Allegation) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) HashSet(java.util.HashSet) UnitOfWork(io.dropwizard.hibernate.UnitOfWork)

Aggregations

Allegation (gov.ca.cwds.rest.api.domain.Allegation)2 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)2 HashSet (java.util.HashSet)2 CrossReport (gov.ca.cwds.rest.api.domain.CrossReport)1 Participant (gov.ca.cwds.rest.api.domain.Participant)1 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)1 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)1 ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)1 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1