Topics: 
client 
    - CM Eligibility
    - CM Enrollment
    - RM Eligibility 
    - RM Enrollment 

Note 
    - CM Setup 

CareMonth
    - CM Enrollment
    - RM Enrollment
    - RM setup 
=====================================================================================================

Client CM Eligibility 

    The relevant fields are: 
        isEligibleForCm = YesNoOrUnknown.UNKNOWN;
	    whyNotEligibleForCmCategory //null 
        whyNotEligibleForCmMemo //null

    Updating Client CM Eligibility 
        /api/client/updateCmEligibility
        void updateCmEligibility
            client.setIsEligibleForCm(...);
            client.setWhyNotEligibleForCmCategory(...);
            client.setWhyNotEligibleForCmMemo(...); 

Client CM Enrollment

    The relevant fields are: 
        isEnrolledInCm = YesNoOrUnknown.UNKNOWN;
        cmEnrollmentConsentMethod //null
        cmEnrollmentConsentMethodMemo; //null

        whyNotEnrolledInCmCategory; //null
        whyNotEnrolledInCmMemo; //null

    Updating Client CM Enrollment 
        /api/client/setIsEnrolledInCmToTrue
        void setIsEnrolledInCmToTrue;
            client.setIsEnrolledInCm(..);
            client.setCmEnrollmentConsentMethod(..);
            client.setCmEnrollmentConsentMethodMemo(..);
        
        /api/client/setIsEnrolledInCmToFalse
        void setIsEnrolledInCmToFalse
            client.setIsEnrolledInCm(...);
            client.setWhyNotEnrolledInCmCategory(...);
            client.setWhyNotEnrolledInCmMemo(...);

    Updating Client CM Enrollment Consent Info 
        /api/client/updateCmEnrollmentConsentInfo
        void updateCmEnrollmentConsentInfo
            client.setCmEnrollmentConsentMethod(...);
            client.setCmEnrollmentConsentMethodMemo(...);

    Updating client "Why not enrolled in CM"
        /api/client/updateWhyNotEnrolledInCm
        void updateWhyNotEnrolledInCm
            client.setWhyNotEnrolledInCmCategory(...);
            client.setWhyNotEnrolledInCmMemo(...);



Client RM Eligibility
    The relevant fields are: 
        isEligibleForRm = YesNoOrUnknown.UNKNOWN;
        whyNotEligibleForRmCategory //null 
        whyNotEligibleForRmMemo //null 

    Updating client RM Eligiblity
        /api/client/updateRmEligibility
        void updateRmEligibility
            client.setIsEligibleForRm(...)
            client.setWhyNotEligibleForRmCategory(...)
            client.setWhyNotEligibleForRmMemo(...)

Client RM Enrollment
    The relevant fields are: 
        isEnrolledInRm = YesNoOrUnknown.UNKNOWN;
        whyNotEnrolledInRmCategory //null 
        whyNotEnrolledInRmMemo //null 

    Updating Client RM Enrollment 
        /api/client/setIsEnrolledInRmToTrue
        void setIsEnrolledInRmToTrue;
            client.setIsEnrolledInRm(...);
            client.setRmReasons(...);

        /api/client/setIsEnrolledInRmToFalse
        void setIsEnrolledInRmToFalse
            client.setIsEnrolledInRm(...);
            client.setWhyNotEnrolledInRmCategory(...);
            client.setWhyNotEnrolledInRmMemo(...);

    Updating client "Why not enrolled in RM"
        /api/client/updateWhyNotEnrolledInRm
        void updateWhyNotEnrolledInRm;
            client.setWhyNotEnrolledInRmCategory(...);
            client.setWhyNotEnrolledInRmMemo(...);    

    Adding client CM/RM reasons
        /api/clientCmRmReason/create
            String clientUid
            CmOrRm cmOrRm
            String code
            String description
            int positionIndex

    NB: 
        - The value of client.isEligibleForRm/Cm is not considered anywhere(e.g enrollment in cm/rm) in the business logic
        - For 'cm setup' to be performed on a note, client must have been 'enrolled in cm'. Currently no similar check on 'rm setup' on care month
        - CM Enrollement requires 'consent method' and 'consent memo'

        - When a care month is created, the following fields are copied from the client to the care month: 
            careMonth.isClientEnrolledInCm = client.isEnrolledInCm
            careMonth.whyNotEnrolledInCmCategory = client.whyNotEnrolledInCmCategory
            careMonth.whyNotEnrolledInCmMemo = client.whyNotEnrolledInCmMemo

            careMonth.isClientEnrolledInRm = client.isEnrolledInRm
            careMonth.whyNotEnrolledInRmCategory = client.whyNotEnrolledInRmCategory
            careMonth.whyNotEnrolledInRmMemo = client.whyNotEnrolledInRmMemo

        - Client CM/RM reasons are copied over as CareMonth CM/RM reasons 
    

Note CM Setup
- The relevant fields are: 
    Note
        Boolean wasCmSetupPerformed;
        String cmSetupDetail;
        String cmSetupNaSignatureStatus;
        String cmSetupMcpSignatureStatus;
        String cmSetupManagerSignatureStatus;
        Claim cmSetupClaim;
    Client 
        Boolean hasCmSetupBeenPerformed = Boolean.FALSE;
    	Note cmSetupNote;

    Marking CM setup as performed on a note: 
        /api/note/markCmSetupPerformed
        void markCmSetupPerformed
            - check client for the note is enrolled in cm 
            - check note does not have active claims 
            - check note client does not have cmSetupNote 
            - check this note is not already marked cm setup performed 
            note.setWasCmSetupPerformed(true);
            note.setCmSetupDetail(cmSetupDetail);
            client.setHasCmSetupBeenPerformed(true);
            client.setCmSetupNote(note);
		    generateClaimSuggestionJson with a line for G0506

    Undoing "markCmSetupPerformed" 
        /api/note/undoMarkCmSetupPerformed
        void undoMarkCmSetupPerformed(AppSession performer, Note note);
            - check this note has cm setup marked as performed 
            - check this note has not active claims 
            note.setWasCmSetupPerformed(false);
            Client client = note.getClient();
            client.setHasCmSetupBeenPerformed(false);
            client.setCmSetupNote(null);
            generateClaimSuggestionJson - refresh the claim suggestion json to remove the G0506 line

    Updating CM Setup detail on a note:
        /api/note/updateCmSetupDetail [NOT IN USE ON THE FRONTEND]
        void updateCmSetupDetail 
            note.setCmSetupDetail(...);

    *Updating CM setup NA signature status: 
        /api/note/updateCmSetupNaSignatureStatus
        void updateCmSetupNaSignatureStatus 
            note.setCmSetupNaSignatureStatus
            TODO: check performer is clients dna 

    *Updating CM Setup MCP signature status 
        /api/note/updateCmSetupMcpSignatureStatus
        void updateCmSetupMcpSignatureStatus 
            - check performer is the note hcp pro 
            - check performer is note client mcpPro
		    note.setCmSetupMcpSignatureStatus(...);

    Updating CM Setup Manager signature status
        /api/note/updateCmSetupManagerSignatureStatus
        void updateCmSetupManagerSignatureStatus
            note.setCmSetupManagerSignatureStatus(...);

    NB:
        - The following fields on the note are currently not supported by the frontend:
            cmSetupNaSignatureStatus
            cmSetupMcpSignatureStatus
        - "cmSetupClaim" is currently not in use.
        - When "cm setup" is performed on a note, The claim generated for the note will have the CM setup code "G0506"
        - Client must be 'enrolled in cm' for cm setup to be performed 
        - When "cm setup" is performed on a note, the following fields are updated on the client: 
            client.hasCmSetupBeenPerformed = Boolean.FALSE;
            client.cmSetupNote;
        - CM setup is done once in the life of a patient ****
        - CM setup can be undone if no claim has been generated on client.cmSetupNote

	
Care Month RM Enrollment: 
    The relevant fields are: 
        Boolean isClientEnrolledInRm;
        String whyNotEnrolledInRmCategory;
        String whyNotEnrolledInRmMemo;
        *Boolean isRmCanceledThisMonth;
	    *String whyIsRmCanceledThisMonth;
    - When a care month is created, this fields are copied over from the corresponding fields on the client
    - Client RM enrollment on a given care month can be modified using the below endpoints  
        /api/careMonth/setIsClientEnrolledInRmToTrue
        void setIsClientEnrolledInRmToTrue
            careMonth.confirmHasNoActiveBillForRm();
            careMonth.setIsClientEnrolledInRm(true);

        /api/careMonth/setIsClientEnrolledInRmToFalse
        void setIsClientEnrolledInRmToFalse
            careMonth.confirmHasNoActiveBillForRm();
            careMonth.setIsClientEnrolledInRm(false);

        /api/careMonth/updateWhyNotEnrolledInRm
        void updateWhyNotEnrolledInRm
            careMonth.confirmHasNoActiveBillForRm();
            careMonth.setWhyNotEnrolledInRmCategory(...);
            careMonth.setWhyNotEnrolledInRmMemo(...);
        
        /api/careMonth/setIsRmCanceledThisMonthToTrue [NOT IN USE ON FRONTEND]             
        void setIsRmCanceledThisMonthToTrue 
            - ensure caremonth has no active rm bill
            careMonth.setIsRmCanceledThisMonth(true);
            careMonth.setWhyIsRmCanceledThisMonth(memo);

        /api/careMonth/updateWhyIsRmCanceledThisMonth [NOT IN USE ON FRONTEND]     
        void updateWhyIsRmCanceledThisMonth 
            careMonth.setWhyIsRmCanceledThisMonth(memo);

        /api/careMonth/setIsRmCanceledThisMonthToFalse [NOT IN USE ON FRONTEND]     
        void setIsRmCanceledThisMonthToFalse 
            careMonth.setIsRmCanceledThisMonth(false);

Care Month CM Enrollment: 
    - The relevant fields are: 
        Boolean isClientEnrolledInCm;
        String whyNotEnrolledInCmCategory;
        String whyNotEnrolledInCmMemo;
        *Boolean isCmCanceledThisMonth;
	    *String whyIsCmCanceledThisMonth;
    - When a new care month is created, this fields are copied over from the corresponding fields on the client 
    - Client CM enrollment on a given care month can be modified using the below endpoints: 
        /api/careMonth/setIsClientEnrolledInCmToTrue
        void setIsClientEnrolledInCmToTrue
            careMonth.confirmHasNoActiveBillForCm();
            careMonth.setIsClientEnrolledInCm(true);

        /api/careMonth/setIsClientEnrolledInCmToFalse
        void setIsClientEnrolledInCmToFalse
            careMonth.confirmHasNoActiveBillForCm();
            careMonth.setIsClientEnrolledInCm(false);

        /api/careMonth/updateWhyNotEnrolledInCm
        void updateWhyNotEnrolledInCm
            careMonth.confirmHasNoActiveBillForCm();
            careMonth.setWhyNotEnrolledInCmCategory(whyNotEnrolledInCmCategory);
            careMonth.setWhyNotEnrolledInCmMemo(whyNotEnrolledInCmMemo);

        /api/careMonth/setIsCmCanceledThisMonthToTrue [CURRENTLY NOT USED ON THE FRONTEND]
        void setIsCmCanceledThisMonthToTrue [NOT IN USE ON FRONTEND]
            - ensure no cm bill for the care month
            careMonth.setIsCmCanceledThisMonth(true);
            careMonth.setWhyIsCmCanceledThisMonth(memo);

        /api/careMonth/updateWhyIsCmCanceledThisMonth [CURRENTLY NOT USED ON THE FRONTEND]
        void updateWhyIsCmCanceledThisMonth [NOT IN USE ON FRONTEND]
            careMonth.setWhyIsCmCanceledThisMonth(memo);

        /api/careMonth/setIsCmCanceledThisMonthToFalse [CURRENTLY NOT USED ON THE FRONTEND]
        void setIsCmCanceledThisMonthToFalse [NOT IN USE ON FRONTEND]
            careMonth.setIsCmCanceledThisMonth(false);

Care Month RM Setup: 
    - The relevant fields are: 
        CareMonth: 
            Boolean wasRmSetupPerformed;
	        Claim rmSetupClaim;

        Client: 
            Boolean hasRmSetupBeenPerformed;
	        CareMonth rmSetupCareMonth;
    - Care month is marked as "rm setup performed" as follows: 
        /api/careMonth/markRmSetupPerformed
        void markRmSetupPerformed
            - ensure careMonth is does not already have hasRmSetupBeenPerformed = true 
            - ensure client for the careMonth does not have rmSetupCareMonth set
            careMonth.setWasRmSetupPerformed(true);
            careMonth.getClient().setHasRmSetupBeenPerformed(true);
            careMonth.getClient().setRmSetupCareMonth(careMonth);
    - The above can be undone as follows:
        /api/careMonth/undoMarkRmSetupPerformed
        void undoMarkRmSetupPerformed(AppSession performer, CareMonth careMonth);
            - check care month wasRmSetupPerformed is marked as true 
            - check no rmSetupClaim exists,
                if one exists and has status = "NEW", cancel it
                if one exists and has status != "NEW", request user to cancel first
            careMonth.setWasRmSetupPerformed(false);
            careMonth.getClient().setHasRmSetupBeenPerformed(false);
            careMonth.getClient().setRmSetupCareMonth(null);

    - The rmSetupClaim is generated using endpoint:
        /api/careMonth/generateRmSetupClaim
        void generateRmSetupClaim
            - check careMonth has wasRmSetupPerformed marked to true
            - check rmSetupClaim does not exis or is cancelled
            - create rmSetupClaim 
            - setRmSetupClaim on the careMonth


Care Month CM/RM Reasons 
    - This are copied over from "clientCmRmReasons" when a new care month is created 
    - They can be updated using the following endpoints 
        /api/careMonthCmRmReason/create
        /api/careMonthCmRmReason/updateBasic

//TODO: Care Month Stats 
	Integer cmTotalTimeInSeconds;
	Integer cmTotalTimeInSecondsByMcp;
	Integer cmTotalTimeInSecondsByCmPro;

	Integer rmTotalTimeInSeconds;
	Integer rmTotalTimeInSecondsByMcp;
	Integer rmTotalTimeInSecondsByRmmPro;
	Integer rmTotalTimeInSecondsByRmePro;
	Integer rmTotalTimeInSecondsByRmsPro;
	Integer rmTotalTimeInSecondsByRmgPro;

	Integer rmNumMeasurementsNotStampedByMcp;
	Integer rmNumMeasurementsNotStampedByNonHcp;
	Integer rmNumMeasurementsNotStampedByRmm;
	Integer rmNumMeasurementsNotStampedByRme;

	Integer numberOfDaysWithRemoteMeasurements;

//TODO: Others 
    Boolean isRmInteractionWaived;
	Boolean isRmTimeWaived;
	Boolean hasAnyoneInteractedWithClientAboutRmOutsideNote;
	Boolean hasMcpRmInteractedByNote;

TODO: TM 
    /api/careMonth/setIsTmThisMonthToTrue
    void setIsTmThisMonthToTrue
        - ensure no CmBill on the care month
		careMonth.setIsTmThisMonth(true);

    /api/careMonth/setIsTmThisMonthToFalse
    void setIsTmThisMonthToFalse
        careMonth.setIsTmThisMonth(false);

TODO: CareMonth CM/RM Bills 
    Bill generateBillForCm [NOT IN USE ON FRONTEND]
        -- refer to implementation logic 

    Bill generateBillForRm 
    -- refer to implementation logic 

