Пример #1
0
  public TrackingLiteVo saveTrackingAndTrackingMovementTimes(
      TrackingLiteVo record,
      TrackingMovementTimesVo trackingMovementTimes,
      CurrentPartialAdmissionForSendToAreaVo partialAdmission,
      Boolean trigersPreAdmissiontoPAS,
      EpisodeofCareVo epOfCare,
      CareContextVo careContext)
      throws StaleObjectException // WDEV-18278
      {
    if (record == null || trackingMovementTimes == null)
      throw new DomainRuntimeException(" Tracking or TrackingMovementTimes are not validated.");

    DomainFactory factory = getDomainFactory();

    Tracking doTracking = TrackingLiteVoAssembler.extractTracking(factory, record);

    factory.save(doTracking);

    TrackingMovementTimes doTrackingMovementTimes =
        TrackingMovementTimesVoAssembler.extractTrackingMovementTimes(
            factory, trackingMovementTimes);
    factory.save(doTrackingMovementTimes);

    if (Boolean.TRUE.equals(trigersPreAdmissiontoPAS)) {
      if (partialAdmission != null) {
        EDPartialAdmission doPartialAdmission =
            CurrentPartialAdmissionForSendToAreaVoAssembler.extractEDPartialAdmission(
                factory, partialAdmission);
        factory.save(doPartialAdmission);
      }

      if (record != null) {
        EDPartialAdmissionDialog dom =
            (EDPartialAdmissionDialog) getDomainImpl(EDPartialAdmissionDialogImpl.class);
        try {
          dom.triggerCancelPartialAdmission(
              record.getAttendance(), record.getCurrentPartialAdmission());
        } catch (DomainInterfaceException e) {
          e.printStackTrace();
        }
      }
    }

    if (careContext != null && epOfCare != null) {
      CareContext doCare = CareContextVoAssembler.extractCareContext(factory, careContext);
      factory.save(doCare);

      EpisodeofCareVo lastEpofcare = getEpisodeOfCare(epOfCare.getID_EpisodeOfCare());
      EpisodeOfCare doEpisode =
          EpisodeofCareVoAssembler.extractEpisodeOfCare(factory, lastEpofcare);
      doEpisode.getCareContexts().add(doCare);
      factory.save(doEpisode);
    }

    return TrackingLiteVoAssembler.create(doTracking);
  }
  private ims.generalmedical.vo.AdmisSummary getAdmissionSummary(
      CareContextShortVo careContext, ClinicalContactShortVo clinicalContact) {
    // Get the Medical Contact, everything else can be retrieved from there.
    DomainFactory factory = getDomainFactory();

    AdmisSummary summaryVo = new AdmisSummary();

    InjuryDetailsVoCollection voCollInjuryDetails = new InjuryDetailsVoCollection();

    String hql = " from InjuryDetails injuryDetails ";
    StringBuffer condStr = new StringBuffer();
    String andStr = " ";

    ArrayList markers = new ArrayList();
    ArrayList values = new ArrayList();

    condStr.append(andStr + " injuryDetails.clinicalContact.contactType = :contactType");
    markers.add("contactType");
    values.add(getDomLookup(ContactType.SPINALMEDICALADMISSION));
    andStr = " and ";

    if (careContext != null) {
      condStr.append(andStr + " injuryDetails.clinicalContact.careContext.id = :id_CareContext");
      markers.add("id_CareContext");
      values.add(careContext.getID_CareContext());
      andStr = " and ";
    } else if (clinicalContact != null) {
      condStr.append(andStr + " injuryDetails.clinicalContact.id = :id_ClinicalContact");
      markers.add("id_ClinicalContact");
      values.add(clinicalContact.getID_ClinicalContact());
      andStr = " and ";
    }

    if (andStr.equals(" and ")) hql += " where ";

    hql += condStr.toString();
    voCollInjuryDetails =
        InjuryDetailsVoAssembler.createInjuryDetailsVoCollectionFromInjuryDetails(
            factory.find(hql, markers, values));

    if (voCollInjuryDetails != null && voCollInjuryDetails.size() > 0) {
      InjuryDetails injury =
          InjuryDetailsVoAssembler.extractInjuryDetails(factory, voCollInjuryDetails.get(0));
      if (injury != null) {
        // 1000 - seconds, 60 - minutes, 60 - hours, 24 - days
        long dayDiff =
            ((((new java.util.Date().getTime()
                                - (injury.getInjuryDate() != null
                                    ? injury.getInjuryDate().getTime()
                                    : 0))
                            / 1000)
                        / 60)
                    / 60)
                / 24;

        if (injury.getInjuryDate() != null)
          summaryVo.setDateOfInjury(new ims.framework.utils.Date(injury.getInjuryDate()));
        summaryVo.setDurationSinceInjury(String.valueOf(dayDiff));

        if (injury.getCauseOfInjury() != null)
          summaryVo.setCauseOfInjury(injury.getCauseOfInjury().getText());
        if (injury.getModeOfInjury() != null)
          summaryVo.setModeOfInjury(injury.getModeOfInjury().getText());
        if (injury.getMechanismOfInjury() != null)
          summaryVo.setMechanismOfInjury(injury.getMechanismOfInjury().getText());
      }
    }

    /*NeuroMotorFindingsVoCollection collNeuroMotorFindings = new NeuroMotorFindingsVoCollection();
    hql = " from NeuExamMotor neuExamMotor";
    condStr = new StringBuffer();
    andStr = " ";

    markers.clear();
    values.clear();

    if(careContext!=null)
    {
    	condStr.append(andStr + " neuExamMotor.careContext.id = :id_CareContext");
    	markers.add("id_CareContext");
    	values.add(careContext.getID_CareContext());
    	andStr = " and ";
    }
    else if(clinicalContact!=null)
    {
    	condStr.append(andStr + " neuExamMotor.clinicalContact.id = :id_ClinicalContact");
    	markers.add("id_ClinicalContact");
    	values.add(clinicalContact.getID_ClinicalContact());
    	andStr = " and ";
    }

    if (andStr.equals(" and "))
    	hql += " where ";

    hql += condStr.toString();
    collNeuroMotorFindings = NeuroMotorFindingsVoAssembler.createNeuroMotorFindingsVoCollectionFromNeuExamMotor(factory.find(hql, markers, values));

    if(collNeuroMotorFindings.size()>0)
    {
    	NeuExamMotor motor = NeuroMotorFindingsVoAssembler.extractNeuExamMotor(factory, collNeuroMotorFindings.get(0));
    	if (motor != null)
    	{
    		if (motor.getLeftMotorLevel() != null)
    			summaryVo.setMotorLeft(motor.getLeftMotorLevel().getName());
    		if (motor.getRightMotorLevel() != null)
    			summaryVo.setMotorRight(motor.getRightMotorLevel().getName());

    		summaryVo.setAsiaScore(getAverrallAsiaScore(motor));
    	}
    }
    */
    NeuroSenastionFindingsVoCollection collNeuroSensationFindings =
        new NeuroSenastionFindingsVoCollection();
    hql = " from NeuExamSens neuExamSens";
    condStr = new StringBuffer();
    andStr = " ";

    markers.clear();
    values.clear();

    condStr.append(andStr + " neuExamSens.clinicalContact.contactType = :contactType");
    markers.add("contactType");
    values.add(getDomLookup(ContactType.SPINALMEDICALADMISSION));
    andStr = " and ";

    if (careContext != null) {
      condStr.append(andStr + " neuExamSens.careContext.id = :id_CareContext");
      markers.add("id_CareContext");
      values.add(careContext.getID_CareContext());
      andStr = " and ";
    } else if (clinicalContact != null) {
      condStr.append(andStr + " neuExamSens.clinicalContact.id = :id_ClinicalContact");
      markers.add("id_ClinicalContact");
      values.add(clinicalContact.getID_ClinicalContact());
      andStr = " and ";
    }

    if (andStr.equals(" and ")) hql += " where ";

    hql += condStr.toString();
    collNeuroSensationFindings =
        NeuroSenastionFindingsVoAssembler.createNeuroSenastionFindingsVoCollectionFromNeuExamSens(
            factory.find(hql, markers, values));

    if (collNeuroSensationFindings.size() > 0) {
      NeuExamSens sensation =
          NeuroSenastionFindingsVoAssembler.extractNeuExamSens(
              factory, collNeuroSensationFindings.get(0));
      if (sensation != null) {
        if (sensation.getFrankleGrade() != null)
          summaryVo.setFrankleGrade(sensation.getFrankleGrade().getText());
        if (sensation.getLeftSensoryLevel() != null)
          summaryVo.setSensoryLeft(sensation.getLeftSensoryLevel().getName());
        if (sensation.getRightSensoryLevel() != null)
          summaryVo.setSensoryRight(sensation.getRightSensoryLevel().getName());
      }
    }

    MSKSpinePathologyFindingVoCollection collMSKSpinePathologyFinding =
        new MSKSpinePathologyFindingVoCollection();

    hql = " from MskSpinePath mskSpinePath ";
    condStr = new StringBuffer();
    andStr = " ";

    markers.clear();
    values.clear();

    condStr.append(andStr + " mskSpinePath.clinicalContact.contactType = :contactType");
    markers.add("contactType");
    values.add(getDomLookup(ContactType.SPINALMEDICALADMISSION));
    andStr = " and ";

    if (careContext != null) {
      condStr.append(andStr + " mskSpinePath.careContext.id = :id_CareContext");
      markers.add("id_CareContext");
      values.add(careContext.getID_CareContext());
      andStr = " and ";
    } else if (clinicalContact != null) {
      condStr.append(andStr + " mskSpinePath.clinicalContact.id = :id_ClinicalContact");
      markers.add("id_ClinicalContact");
      values.add(clinicalContact.getID_ClinicalContact());
      andStr = " and ";
    }

    condStr.append(andStr + " mskSpinePath.isPrimaryPathology = :isprimary");
    markers.add("isprimary");
    values.add(Boolean.TRUE);
    andStr = " and ";

    if (andStr.equals(" and ")) hql += " where ";

    hql += condStr.toString();

    collMSKSpinePathologyFinding =
        MSKSpinePathologyFindingVoAssembler
            .createMSKSpinePathologyFindingVoCollectionFromMskSpinePath(
                factory.find(hql, markers, values));

    // java.util.List pathLst = factory.find(domContact.getMskPath(), " where
    // this.isPrimaryPathology = :primary", new String[]{"primary"}, new Object[]{Boolean.TRUE});
    // Should only be one returned
    if (collMSKSpinePathologyFinding != null && collMSKSpinePathologyFinding.size() > 0) {
      MskSpinePath path =
          MSKSpinePathologyFindingVoAssembler.extractMskSpinePath(
              factory, collMSKSpinePathologyFinding.get(0));
      if (path.getPathSite() != null)
        summaryVo.setLevelOfInjury(path.getPathSite().getDescription());
      if (path.getTypeOfInjury() != null)
        summaryVo.setTypeOfInjury(path.getTypeOfInjury().getText());
    }

    NeuroInterpretVoCollection collNeuroInterpretVo = new NeuroInterpretVoCollection();
    hql = " from NeuInterpret neuInterpret";
    condStr = new StringBuffer();
    andStr = " ";

    markers.clear();
    values.clear();

    condStr.append(andStr + " neuInterpret.clinicalContact.contactType = :contactType");
    markers.add("contactType");
    values.add(getDomLookup(ContactType.SPINALMEDICALADMISSION));
    andStr = " and ";

    if (careContext != null) {
      condStr.append(andStr + " neuInterpret.careContext.id = :id_CareContext");
      markers.add("id_CareContext");
      values.add(careContext.getID_CareContext());
      andStr = " and ";
    } else if (clinicalContact != null) {
      condStr.append(andStr + " neuInterpret.clinicalContact.id = :id_ClinicalContact");
      markers.add("id_ClinicalContact");
      values.add(clinicalContact.getID_ClinicalContact());
      andStr = " and ";
    }

    if (andStr.equals(" and ")) hql += " where ";

    hql += condStr.toString();
    collNeuroInterpretVo =
        NeuroInterpretVoAssembler.createNeuroInterpretVoCollectionFromNeuInterpret(
            factory.find(hql, markers, values));

    if (collNeuroInterpretVo != null && collNeuroInterpretVo.size() > 0) {
      NeuInterpret interpret =
          NeuroInterpretVoAssembler.extractNeuInterpret(factory, collNeuroInterpretVo.get(0));
      if (interpret != null) {
        if (interpret.getSpinalSyndrome() != null)
          summaryVo.setSpineSyndrome(interpret.getSpinalSyndrome().getText());
        if (interpret.getAsiaGrade() != null)
          summaryVo.setAsiaGrade(interpret.getAsiaGrade().getText());
        if (interpret.getOverallNeuroLevel() != null)
          summaryVo.setOverallNeuro(interpret.getOverallNeuroLevel().getName());
        if (interpret.getCompleteIncomplete() != null)
          summaryVo.setCompleteIncomplete(interpret.getCompleteIncomplete().getText());
      }
    }

    // Get the First Admission date for this patient.
    EpisodeofCareVo voEpisodeOfCare = null;
    CareContextVoCollection collCareContextVo = null;
    markers.clear();
    values.clear();

    if (careContext != null)
      voEpisodeOfCare =
          EpisodeofCareVoAssembler.create(
              (EpisodeOfCare)
                  factory.getDomainObject(
                      EpisodeOfCare.class, careContext.getEpisodeOfCare().getID_EpisodeOfCare()));
    else if (clinicalContact != null) {
      CareContextVo voCareContext =
          CareContextVoAssembler.create(
              (CareContext)
                  factory.getDomainObject(
                      CareContext.class, clinicalContact.getCareContext().getID_CareContext()));
      voEpisodeOfCare =
          EpisodeofCareVoAssembler.create(
              (EpisodeOfCare)
                  factory.getDomainObject(
                      EpisodeOfCare.class, voCareContext.getEpisodeOfCare().getID_EpisodeOfCare()));
    }

    collCareContextVo = voEpisodeOfCare.getCareContexts().sort();

    if ((collCareContextVo != null) && (collCareContextVo.size() > 0))
      for (int i = 0; i < collCareContextVo.size(); i++) {
        if (collCareContextVo.get(i).getContext().equals(ContextType.INPATIENT))
          summaryVo.setFirstAdmissionDate(collCareContextVo.get(i).getStartDateTime().getDate());
      }

    // MRSA record.
    MRSASitesResultsVoCollection collMRSAVo = new MRSASitesResultsVoCollection();
    hql = "select siteres from MRSAAssessment t join t.sitesAndResults as siteres ";
    condStr = new StringBuffer();
    andStr = " ";

    markers.clear();
    values.clear();

    condStr.append(andStr + " t.clinicalContact.contactType = :contactType");
    markers.add("contactType");
    values.add(getDomLookup(ContactType.SPINALMEDICALADMISSION));
    andStr = " and ";

    if (careContext != null) {
      condStr.append(andStr + " t.careContext.id like :cc");
      markers.add("cc");
      values.add(careContext.getID_CareContext());
      andStr = " and ";
    } else if (clinicalContact != null) {
      condStr.append(andStr + " t.clinicalContact.id like :cc");
      markers.add("cc");
      values.add(clinicalContact.getID_ClinicalContact());
      andStr = " and ";
    }

    condStr.append(andStr + " siteres.result = :res");
    markers.add("res");
    values.add(getDomLookup(MRSAResult.POSITIVE));
    andStr = " and ";

    hql += " where " + condStr.toString();

    collMRSAVo =
        MRSASitesResultsVoAssembler.createMRSASitesResultsVoCollectionFromMRSASitesResults(
            factory.find(hql, markers, values));

    if (collMRSAVo != null && collMRSAVo.size() > 0) summaryVo.setMRSAStatus(Boolean.TRUE);
    else summaryVo.setMRSAStatus(Boolean.FALSE);

    return summaryVo;
  }