This case requires us to determine the proper allocation of the costs of health care for Medicaid-funded residents of a nursing home in the period between the home's voluntary withdrawal from participation as a Medicaid provider and the successful relocation of the patients to other facilities. The question, clearly one for which none of the parties had planned, was at the relevant time not addressed directly by any state or federal statute or regulation. Viewing the matter primarily as one of contractual interpretation, we affirm the district court's ruling that the state was required to pay for such care at the rate paid prior to the home's withdrawal.

2

* The plaintiff, Newfield House, Inc. ("Newfield House" or "the home"), a nursing-home health-care facility duly licensed by the Massachusetts Department of Public Health, served as a provider of nursing home services in the Medicaid program since the inception of the program in Massachusetts. Newfield House provided care for both Medicaid and non-Medicaid patients, charging a rate of $19.70 per day for the former and $25.00 per day for the latter. Until May 1975, Newfield House, apparently like other nursing home providers in Massachusetts, participated in the Medicaid program without any written agreement. On May 17, 1975, the federal Department of Health, Education and Welfare (HEW) sent a letter to the Massachusetts Department of Public Welfare (DPW), directing it to enter into written provider contracts with all nursing home providers as a condition of receiving the 50 percent federal financial participation provided by the program. Newfield House received DPW's proposed provider contract on May 30, and immediately replied that it would not continue as a Medicaid provider under the terms of that agreement. It proposed an alternative agreement, under which it would continue to provide services for the ten patients then receiving Medicaid payments, but only at its higher private patient rate. DPW rejected this offer, and Newfield House refused to sign an agreement providing for limited interim continuation at the prior Medicaid rate. DPW informed Newfield House on August 24, 1976 that, because the home had not signed a provider agreement, DPW would terminate Medicaid payments to it as of October 1, 1976.

3

Prior to October 1, Newfield House brought suit in Massachusetts Superior Court to enjoin DPW from terminating payments to it for its ten Medicaid patients unless and until the department relocated the patients to other facilities. The court entered a temporary restraining order directing DPW to pay for nursing home services for the home's Medicaid patients at the home's private patient rate of $25 per day. The order was initially continued for 15 days by agreement of the parties, and was subsequently ordered continued while the case was assigned for trial on an expedited basis.

4

Before trial was to begin, however, DPW removed the case to federal district court, and that court denied Newfield House's motion to remand the case to state superior court. Defendants moved to dissolve the state court restraining order, but the district court maintained the order in effect and ultimately denied the motion on grounds of mootness. With the district court's permission, Newfield House added the Secretary of HEW, the Massachusetts Department of Public Health (DPH), and the Medicaid-funded patients then residing at the home as defendants. In addition, DPW brought a counterclaim against Newfield House seeking return of all money paid under the restraining order, and Newfield House added its Medicaid patients as third-party defendants on that counterclaim. Both Newfield House and some of the patients' families petitioned the court for appointment of a guardian ad litem to represent the patients, but the district court declined to act on the petitions and, with one limited exception, no patient ever appeared in the case. At the close of the case, the court granted HEW's motion to dismiss it from the action.

5

On the central issue presented, the district court ordered Newfield House to repay to DPW the excess of the payments made under its interim order at the home's private patient rate of $25 per day over the amount that would have been due at its Medicaid rate of $19.70 per day, but only that excess (a total of $8,538.74 of the $53,305.31 paid). The court first drew a sharp distinction between voluntary and involuntary terminations of nursing home provider arrangements, and held that the federal Medicaid regulations in force at all times relevant here imposed no obligation on the state to provide such payments in the case of a voluntary termination. But the court went on to conclude that "unusual circumstances" present in this case supported a finding of a "constructive provider agreement" between the state and the home during the pendency of this dispute citing such circumstances as the uncertainty surrounding the parties' obligations, the fact that the state would have been required "with minor exceptions" to provide care for Newfield House's patients at the same or greater rates at other facilities, and the existence of the temporary restraining order issued by the state court and continued by the federal court.

6

Emphasizing that providing for the care of the patients had been its central concern throughout the litigation, the court stressed that such relevant equitable/contractual factors as unjust enrichment and detrimental reliance in its view mitigated against the state and in favor of the home and its patients. The court held that its refusal to return to the state all the payments made to the home did not violate the Eleventh Amendment, since such payments had been prospective with respect to the then-valid interim orders pursuant to which they were made. Finally, the court suggested that the state pursue administrative remedies seeking reimbursement from the federal government, expressing the view that while it could not order such reimbursement (since the state had not exhausted available administrative remedies) it did not think those remedies necessarily futile.

II

7

The central issue posed by this case is whether either federal statutes and regulations or the state's own prior actions require the state to pay Newfield House for care provided to Medicaid-eligible patients between the time Newfield House withdrew from the Medicaid program and the time those patients were successfully relocated. We agree with the district court that while federal Medicaid provisions do not themselves require such payments, the state's essentially contractual dealings with the home, viewed in light of relevant equitable considerations, do obligate it to reimburse the home for the services provided. We note that this precise legal question will not recur in Massachusetts, since the state has subsequently sought to do precisely what our analysis suggests it must do to avoid such a liability: enact legislation placing the burden of interim or relocation costs on providers. We of course express no view on the actual effect of that statute or subsequent regulations. See Mass.Gen.L. ch. 118, § 4; 106 C.M.R. § 456.401-05.

8

We first focus on Newfield House's attempt to find a basis in federal law for imposing a duty upon the state to relocate patients or pay for their continued care at a withdrawing facility. Its argument relies on one HEW regulation, 42 C.F.R. § 449.10(b)(15)(v) (1977), on two interpretations of that regulation, and on two related HEW guidelines. The regulation provides that a state can receive federal funds for payments for up to 30 days care to an institution whose provider agreement "has expired or otherwise terminated", but only for previously admitted patients and most critically only "if the state agency makes a showing satisfactory to the Secretary that it has made reasonable efforts to facilitate the orderly transfer of such individuals from such facility to another facility". Two HEW documents interpret this regulation. First, and most favorably to the plaintiff, a manual issued by HEW's Office of Nursing Home Affairs, apparently applicable even where a facility voluntarily withdraws from Medicaid, sets forth a view of relocation responsibilities that strongly implies state responsibility for relocation costs and interim expenses.1 Second, following HEW's agreement to a consent decree of general applicability in Cornell v. Creasy, 491 F.Supp. 124 (N.D.Ohio 1978), and subsequent to the events at issue in this case, HEW's Health Care Finance Administration issued guidelines detailing state agencies' responsibilities for transferring patients.2 In addition, other divisions of HEW have in other contexts manifested a similar general understanding: the Office of Human Development/Administration on Aging issued a Technical Assistance Memorandum designed to aid state agencies having the "primary responsibility" for developing relocation plans for nursing home patients while the Public Health Service has indicated a similar view and has promulgated a Model State Relocation Plan for use by the states in planning for relocations.

9

Although as discussed below we think this regulatory background significant, we agree with the district court that it is insufficient by itself to impose a binding legal obligation on a state. The regulation serves only to establish conditions precedent to a state's ability to gain recompense from the federal government if it decides to spend certain funds; it in no way mandates the expenditure of any funds. HEW's interpretations of that regulation, while perhaps suggesting a different view, can only clarify and cannot alter or expand the scope of those preconditions. Finally, the other HEW guidelines do not purport to do anything other than offer informal assistance, and are clearly of no binding force on the states.

10

In light of this conclusion, we think this dispute must be viewed primarily as a contractual problem. Our task in such matters is one of resolving the obviously unanticipated problem that has arisen in a way that effectuates the parties' contractual intent, see 3 Corbin, Contracts § 534 (1960), or, if it is clear that the parties had no meaningful intent as to the matter, as one of construing their dealings so as to give them the most appropriate legal effect, see Corbin, supra, § 622.3 Put another way, we look here first to the intended terms of what we discern as an actual implied-in-fact contract between the parties and then to the terms imposed in any event by the constructive quasi-contract implied in law between them. We address each of these in turn.

11

In supplying a term omitted from the implied actual contract, our focus must be on what it is likely that the parties would have agreed upon had they focused on the problem. As a result, while we have rejected the argument that federal law directly obligates a state to pay the relevant costs, we think the provisions described above must be considered relevant as a backdrop against which the parties' contractual expectations are to be assessed. Specifically, we think that those provisions serve to create a presumption or expectation that a state will pay for patient care during relocation efforts following a voluntary withdrawal, putting a burden on it to make clear, by law or contract, any extent to which contracting facilities would be liable for such expenses instead.4 Such a burden, of course, might be thought to rest on the state by operation of general contract principles even in the absence of this regulatory background, since in such contractual dealings the state will be the party that both furnishes the standard agreement and that possesses greater general experience with the relevant conditions. But these federal provisions put the state on direct notice that it would likely be presumed liable for the kind of costs involved here unless it took affirmative steps to dispel that presumption.5

12

We find, however, that Massachusetts not only took no such affirmative liability-disclaiming steps, but in addition took several steps in its role as contractor that reinforced the suggestion that it would pay such costs. First, DPW relocated patients if a facility was terminated from the Medicaid program because of inadequate patient care,6 and reimbursed facilities for care of patients who remained at a home pending transfer after a decertification. Similarly, it had written to Newfield House specifically, just before the events relevant to this case began, asserting that it would remove the home's Medicaid patients if applicable safety regulations were not met. See Klein v. Califano, 586 F.2d 250, 257 (3d Cir. 1978) (dictum) (state Medicaid agency required to transfer residents upon decertification of nursing home). Second, the state had provided assistance to Newfield House in relocating patients, by paying their transportation expenses, contacting other facilities to seek notification of vacancies and priority admissions, and providing other forms of what it characterizes as "gratuitous assistance".7 Third, the department acknowledged that it would pay the full cost of patient care after a patient's own resources had expired. Fourth, the state appeared to acknowledge that it would be required to assist a facility that was withdrawing if that facility had signed a written provider agreement, although it later denied that suggestion. Fifth, DPW had a policy of requiring facilities to get the prior consent of a patient and the patient's family to a transfer, and did not anticipate that Newfield House would move any patients without such consent; given many patients' predictable reluctance to move, and the shortage of alternative beds available, see n.10 infra, this policy had the predictable effect of requiring homes to provide interim care for patients. Sixth, DPW has never disputed the fact that pursuant to the federal regulation cited above it was entitled to federal financial participation for at least the first 30 days of care provided by a facility subsequent to its withdrawal from Medicaid. Finally, in the face of all these indications, the state never informed nursing homes that they might be required to pay for care in such circumstances until after this controversy had arisen,8 and never informed any individual patients of either that possibility or even of the fact that Newfield House was withdrawing from the program.

13

Taking these actions in conjunction with the presumption created by the federal guidelines, we conclude that the contract between Massachusetts and Newfield House must be interpreted as requiring the state to continue to pay for care until the home's patients were relocated. At the same time, however, we emphasize the relative rarity of holding a state to be contractually bound to pay for services in an area of social programs so largely governed by statutes and regulations. Finding such an obligation necessarily requires an intensive fact-specific inquiry, and we infer one here only because we find the facts relevant to the contract so compelling. See generally Monmouth Medical Center v. State of New Jersey, 80 N.J. 299, 403 A.2d 487 (1979). We note as well that such an interpretation could well be countervailed by evidence of bad faith or unreasonable activity on the part of a provider, no evidence of which has been presented here.

14

In addition, we note that even were we not to find the express contract between the parties applicable to this situation we think this case would be an appropriate instance for the application of such quasi-contractual doctrines as quantum meruit and unjust enrichment. See generally 5 Corbin, supra, §§ 1102-21; Fuller and Eisenberg, Basic Contract Law 70-72 (3d ed. 1972). Like the district court, we give significant weight to the fact that the state would "with minor exceptions" have been required to pay these patients' expenses in another home had they been transferred immediately upon Newfield House's withdrawal.9 In addition, we take note of the undisputed fact that Newfield House provided quality care throughout this period, and of the equally undisputed fact that its Medicaid rates even its private rates were less than the Medicaid rates of other nearby nursing home providers. Moreover, we think Newfield House has satisfied other elements of a recovery in quantum meruit: it has provided its services under circumstances which put the state on notice that it expected to be paid, see Sachs v. Continental Oil Co., 454 F.Supp. 614 (E.D.Pa.1978), it has itself had a reasonable expectation of being paid, see Turner v. Unification Church, 473 F.Supp. 367 (D.R.I.1978), aff'd mem., 602 F.2d 458 (1st Cir. 1979), and it has provided substantial good-faith performance of its obligations under the contract, Franchi Const. Co. v. Combined Ins. Co., 580 F.2d 1 (1st Cir. 1978).10 Cf. Ferber Co. v. Ondrick, 310 F.2d 462, 466 (1st Cir. 1962) (awarding quantum meruit recovery in private lawsuit involving similar factual elements).

15

Having concluded that Newfield House is entitled to payment for the services it has rendered the state, we must determine the rate at which those services should be recompensed. On a straightforward contract interpretation theory terms of the contract are simply extended to cover the period not provided for, and the rate of payment is simply extended as well. Quasi-contractual remedies would dictate the same amount of recovery: the reasonable value of the goods or services furnished on a theory of quantum meruit, and the amount of benefit gained by the recipient on a theory of restitution.11 See Fuller and Eisenberg, supra, at 70; Interform Co. v. Mitchell, 575 F.2d 1270 (9th Cir. 1978) (while quantum meruit focuses on value of goods or services and restitution focuses on value of benefit, generally the two will not differ); cf. Beaumont Birch Co. v. Najjar Industries, Inc., 477 F.Supp. 970, 974 n. 10 (S.D.N.Y.1979) (contract price may be used as evidence of quantum meruit recovery even where plaintiff produced evidence showing actual value had been higher). Accordingly, we agree with the district court that the proper rate of payment should be Newfield House's prior Medicaid rate of $19.70 per day.12 See generally Kaye v. Whalen, 56 A.D.2d 111 (3d Dept. 1977), aff'd mem., 44 N.Y.2d 754, 405 N.Y.S.2d 682, 376 N.E.2d 1327, app. dismissed for want of a substantial federal question, 439 U.S. 922, 99 S.Ct. 303, 58 L.Ed.2d 315 (1978).

III

16

While our holdings above have disposed of the central issues in this case, we must also resolve Newfield House's claims that both the federal government and the home's Medicaid patients should have been added to this action as third-party defendants.13 We think the district court's dismissal of each of these claims to be correct. With respect to the federal government, we do not reach the merits of its underlying contention that it is not required to reimburse the state for the payments made to Newfield House; we simply agree that Newfield House, being entitled to payment by the state, had no direct claims against the federal government, and, like the district court, we refer the state initially to its administrative recourse against the federal government.14 See 42 U.S.C. § 1316(d); 42 C.F.R. § 442.30(c). With respect to the patients, we think Newfield House's claim foreclosed by our finding that the terms of its contract with the state simply extended to the period in question, particularly in light of the home's failure to take any steps to dispel that expectation in advance of the events at issue here. One of those terms was obviously that Newfield House would seek no additional payment from Medicaid-funded patients, and we think it bound by that provision during this period fully as much as the state is bound by its contractual commitments.

Section 6062 of the Office's Long Term Care Manual states: "(The state) has the primary responsibility for deciding that such patients are to be relocated ... and for ensuring their safe and orderly transfer from a facility that no longer participates in Medicaid to another participating facility. The fact that a facility no longer participates in Federal programs does not mean that patients who rely on medical assistance to pay for care will necessarily be relocated. Many of the patients may be providing pay or the State may decide to pay 100 per cent of the cost of care of medical assistance patients. Regardless of the facility's status under the Federal programs, the State remains responsible for the care and services provided therein to public assistance patients and for making decisions, as appropriate, to transfer such patients to other Medicaid participating facilities.... Each State should develop a State long term care patient relocation plan for the orderly transfer of patients. In specific terms, the plan should provide for: decisions to be made on relocation of patients on a case-by-case basis; ...." (detailed specifications omitted)

The guidelines assert that the consent decree "set forth HEW's interpretations of the State agencies' obligations to provide for an 'orderly transfer' of the recipient in cases of mass transfers due to a facility's decertification or withdrawal from the Medicaid program. HEW interprets 'transfer' to be a process rather than a short period of time covering a physical relocation. The Departmental interpretation reflects existing policy position in specifying minimum regulatory requirements.... In order for the transfer process to be orderly, the State agency must meet at least the following requirements: a. the nature and severity of the facility's failure to meet required standards must be considered; b. the availability of suitable, alternative facilities must be considered; ...." (detailed specifications omitted)

We think it clear that we have jurisdiction over these state law claims as claims properly pendent to the substantial federal claims we have rejected. See United Mine Workers v. Gibbs, 383 U.S. 715, 86 S.Ct. 1130, 16 L.Ed.2d 218 (1966). In addition, we agree that the relief ordered by the district court is not barred by the Eleventh Amendment. We need not decide whether a federal court could restrain state officials solely under a pendent state law claim, for we conclude that the state has waived its rights under that amendment by having the case removed to federal court. While the standard for finding a waiver is high, see Edelman v. Jordan, 415 U.S. 651, 673, 94 S.Ct. 1347, 1360, 39 L.Ed.2d 662 (1974), one long-accepted basis for such a finding is a general appearance in a federal proceeding by a state official acting within his authority. See Clark v. Barnard, 108 U.S. 436, 447, 2 S.Ct. 878, 882, 27 L.Ed. 780 (1883); Ford Motor Co. v. Department of Treasury of Indiana, 323 U.S. 459, 467-70, 65 S.Ct. 347, 352-53, 89 L.Ed. 389 (1945); Sosna v. Iowa, 419 U.S. 393, 396 n. 2, 95 S.Ct. 553, 555 n. 2, 42 L.Ed.2d 532 (1975). The state's actions here seeking removal, arguing in opposition to plaintiff that the Eleventh Amendment did not bar federal jurisdiction over either the case as a whole or pendent claims in particular, see 28 U.S.C. § 1441(c), and pressing a counterclaim in federal court present a far clearer case of waiver than does a mere appearance. The state Attorney General has necessarily represented that he has such power by haveing this case removed, and we have found nothing in our review of Massachusetts law to contradict this view. See Board of Educ. v. Assessors of Worcester, 368 Mass. 511, 515, 333 N.E.2d 450 (1975). The Attorney General has broad power to direct state litigation in all forums, see Mass.Gen.L. ch. 12 § 3; ch. 258 § 6; Feeney v. Commonwealth, 373 Mass. 359, 366 N.E.2d 1262 (1977); Secretary of Administration v. Attorney General 367 Mass. 154, 162-65, 326 N.E.2d 334 (1975), and has all powers reasonably necessary or incidental to his office, see Multi-Line Ins. Rating Bureau v. Commission of Ins., 357 Mass. 19, 22, 255 N.E.2d 787 (1970); (1975) Mass. Att'y Gen'l Rep. 40 (Op. N. 1, July 2, 1974). In light of the several factors cited above, its attempt now to invoke the Eleventh Amendment would if allowed work a virtual fraud on the federal court and opposing litigants. Eisler v. Stritzler, 535 F.2d 148, 151-52 (1st Cir. 1976), involving non-conferrable jurisdiction rather than waivable immunity, sanctions no such abuse, and we will not do so now

We think it clear, despite the state's half-hearted assertions to the contrary, that nothing in the federal Medicaid scheme prohibited payments of the kind made here, and equally clear that a state may contractually obligate itself for care for which it will receive no federal participation

It is conceded that the state had no plan specifically providing for the relocation of Medicaid patients following a provider's voluntary withdrawal from the program at the time this case arose, and it is also agreed that it does have such a plan now, placing unspecified relocation responsibilities on the facility

A state official testified that the instant case is the first instance of a home voluntarily withdrawing from the Medicaid program in this manner; the state's answer to a query by the district court indicated that there had been one prior such withdrawal, and that the state had provided only "gratuitous assistance"

DPW acknowledged that the state had a significant policy interest in reducing the "transfer trauma" suffered by many nursing home residents upon relocation. Similarly, in a newspaper article submitted as an exhibit at trial, the state's secretary of human services was quoted as stating that the state had a practical if not a legal responsibility to provide relocation of Medicaid patients. Data provided by "relocation teams" employed by the state for this purpose suggest that they assisted in non-jeopardy as well as jeopardy situations

DPW's standard-form Agreement With Intermediate Care Facilities, which includes Newfield House, provides that transfers shall take place in accordance with a chapter of a Medical Care Plan, which until amended in October 1976 (just after Newfield House brought this suit) provided that DPW would "remove and relocate" patients in cases where facilities had been sanctioned for violations. The Agreement goes on to state that finding suitable alternate placements "shall be the joint responsibility of the Department and the provider." It requires the facility in relevant part only to provide 30 days notice of withdrawal, (which one state witness testified was currently being changed to six months), and obliges the state to allow a parallel 30 days for patient transfer in the event of decertification

To the extent that equitable remedies require that a plaintiff not have "unclean hands" in any manner, we note that there is no suggestion in the record that Newfield House acted in any bad faith or dilatory fashion in withdrawing from the program or in attempting to relocate its residents. While one state official denied that there were no beds available to receive the patients, and another had no information, a third repeatedly acknowledged a shortage of beds. A Newfield House administrator testified that she expected the transfer to take 10-12 months, and Newfield House introduced evidence of diligent efforts to relocate. While the state's data on relocation times suggested that the time required here was longer than usual, this could well have been explained by an increasing shortage of beds. Indeed, insofar as providing adequate beds is a responsibility of the state as an HEW administrator testified that it was failure to provide adequate beds is another factor tilting the equitable balance toward state payment. The state defendants would find unreasonable conduct in Newfield House's refusal to accept the state's proferred limited interim provider agreement, while Newfield House finds the state's refusal of its counter-offer to provide services at its private patient rate unreasonable. We think these actions the least favorable aspect of the case for the home, but conclude that they are insufficient to relieve the state of its obligation to pay at the lower rate

We think Newfield House's argument that the state's failure to secure an injunction bond from it precludes recovery of monies paid pursuant to the injunction to be specious. The state is clearly correct that the need for a bond is limited to the recovery of damages and has no application to a claim for restitution of amounts subsequently found to have been undue. Arkadelphia Milling Co. v. St. Louis S.W. Ry. Co., 294 U.S. 134, 39 S.Ct. 237, 63 L.Ed. 517 (1919); Middlewest Motor Freight Bureau v. United States, 433 F.2d 212 (8th Cir. 1979), cert. denied, 402 U.S. 999, 91 S.Ct. 2169, 29 L.Ed.2d 165 (1971)

Our conclusion that Newfield House is entitled to payment by the state at the full rate of the state's prior payments makes it unnecessary for us to consider the home's claim that it was entitled to notice and a hearing prior to the state's termination of payments

The record is somewhat unclear as to the current status of federal payments to the state. It appears that the federal government has continued to make all payments claimed by the state, while simultaneously expressing an intent to seek subsequent disallowance of the payments at issue here. The central issue appears to be whether the state could become eligible for federal financial participation in its payments to Newfield House by executing a "retroactive provider agreement"; while Newfield House and the state are agreeable to this resolution, the federal government thus far is not. We do not regard earlier expressions of the federal government's views in this matter as conclusive, in part because they have not been based on full administrative proceedings and in part because they have preceded the district court's and our finding that a constructive provider agreement did exist during the relevant period